Skip to content

Commit 5b24bbe

Browse files
authored
Merge pull request #93 from orxfun/handle-zst-in-concurrent-pinned-vec
Handle zst in concurrent pinned vec
2 parents 1411868 + d13df24 commit 5b24bbe

41 files changed

Lines changed: 665 additions & 215 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/algorithms/tests/binary_search.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::algorithms::binary_search::binary_search_by;
2-
use crate::{Growth, SplitVec, test_all_growth_types};
2+
use crate::{Fragment, Growth, SplitVec, test_all_growth_types};
33
use core::cmp::Ordering;
44
use orx_pinned_vec::PinnedVec;
55

@@ -20,14 +20,17 @@ fn bin_search_empty() {
2020
fn bin_search_empty_first_fragment() {
2121
let cmp = get_compare(42);
2222

23-
let fragments = alloc::vec![alloc::vec![].into()];
23+
let fragments = alloc::vec![Fragment::new_empty(4)];
2424
let result = binary_search_by(&fragments, cmp);
2525
assert_eq!(result, Err(0));
2626
}
2727

2828
#[test]
2929
fn bin_search_empty_second_fragment() {
30-
let fragments = alloc::vec![alloc::vec![1, 4, 5].into(), alloc::vec![].into()];
30+
let fragments = alloc::vec![
31+
Fragment::new(4, alloc::vec![1, 4, 5]),
32+
Fragment::new_empty(4)
33+
];
3134

3235
let result = binary_search_by(&fragments, get_compare(0));
3336
assert_eq!(result, Err(0));
@@ -51,9 +54,9 @@ fn bin_search_empty_second_fragment() {
5154
#[test]
5255
fn bin_search_three_fragments() {
5356
let fragments = alloc::vec![
54-
alloc::vec![1, 4, 5].into(),
55-
alloc::vec![7].into(),
56-
alloc::vec![9, 10].into()
57+
Fragment::new(3, alloc::vec![1, 4, 5]),
58+
Fragment::new(1, alloc::vec![7]),
59+
Fragment::new(2, alloc::vec![9, 10]),
5760
];
5861

5962
let search = |x| binary_search_by(&fragments, get_compare(x));

src/algorithms/tests/in_place_sort.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use test_case::test_case;
88

99
#[test]
1010
fn insertion_position() {
11-
let fragment: Fragment<u32> = alloc::vec![4, 7, 9, 13, 16, 17, 23].into();
11+
let vec = alloc::vec![4, 7, 9, 13, 16, 17, 23];
12+
let fragment = Fragment::new(vec.capacity(), vec);
1213

1314
let mut c = |a: &u32, b: &u32| a.cmp(b);
14-
let mut pos = |val: &u32| find_position_to_insert(&fragment, &mut c, val);
15+
let mut pos = |val: &u32| find_position_to_insert(fragment.as_slice(), &mut c, val);
1516

1617
assert_eq!(pos(&0), None);
1718
assert_eq!(pos(&3), None);
@@ -52,16 +53,16 @@ fn insertion_position() {
5253
fn insertion_position_with_ties() {
5354
let mut c = |a: &u32, b: &u32| a.cmp(b);
5455

55-
let fragment: Fragment<u32> = alloc::vec![4, 7, 13, 13, 13, 17, 23].into();
56-
let mut pos = |val: &u32| find_position_to_insert(&fragment, &mut c, val);
56+
let fragment: Fragment<u32> = Fragment::new(12, alloc::vec![4, 7, 13, 13, 13, 17, 23]);
57+
let mut pos = |val: &u32| find_position_to_insert(fragment.as_slice(), &mut c, val);
5758
assert_eq!(pos(&13), Some(2));
5859

59-
let fragment: Fragment<u32> = alloc::vec![4, 7, 13, 13, 23, 23, 23].into();
60-
let mut pos = |val: &u32| find_position_to_insert(&fragment, &mut c, val);
60+
let fragment: Fragment<u32> = Fragment::new(12, alloc::vec![4, 7, 13, 13, 23, 23, 23]);
61+
let mut pos = |val: &u32| find_position_to_insert(fragment.as_slice(), &mut c, val);
6162
assert_eq!(pos(&23), Some(4));
6263

63-
let fragment: Fragment<u32> = alloc::vec![4, 4, 13, 13, 23, 23, 23].into();
64-
let mut pos = |val: &u32| find_position_to_insert(&fragment, &mut c, val);
64+
let fragment: Fragment<u32> = Fragment::new(12, alloc::vec![4, 4, 13, 13, 23, 23, 23]);
65+
let mut pos = |val: &u32| find_position_to_insert(fragment.as_slice(), &mut c, val);
6566
assert_eq!(pos(&4), None);
6667
}
6768

@@ -70,9 +71,9 @@ fn sort_simple() {
7071
let mut c = |a: &u32, b: &u32| a.cmp(b);
7172

7273
let mut fragments: Vec<Fragment<u32>> = alloc::vec![
73-
alloc::vec![2, 4].into(),
74-
alloc::vec![0, 5, 6].into(),
75-
alloc::vec![1, 3].into()
74+
Fragment::new(4, alloc::vec![2, 4]),
75+
Fragment::new(4, alloc::vec![0, 5, 6]),
76+
Fragment::new(4, alloc::vec![1, 3]),
7677
];
7778

7879
in_place_sort_by(&mut fragments, &mut c);
@@ -97,7 +98,7 @@ fn sort_growth(growth: impl Growth) {
9798
for _ in 0..num_fragments {
9899
let fragment_capacities: Vec<_> = fragments.iter().map(|x| x.capacity()).collect();
99100
let mut fragment =
100-
Fragment::new(growth.new_fragment_capacity_from(fragment_capacities.into_iter()));
101+
Fragment::new_empty(growth.new_fragment_capacity_from(fragment_capacities.into_iter()));
101102
for i in 0..fragment.capacity() {
102103
let i = len + i;
103104
let value = match i % 3 {
@@ -121,7 +122,10 @@ fn sort_growth(growth: impl Growth) {
121122
}
122123

123124
fn assert_is_sorted<T: Ord>(fragments: Vec<Fragment<T>>) {
124-
let flattened: Vec<T> = fragments.into_iter().flat_map(|x| Vec::from(x)).collect();
125+
let flattened: Vec<T> = fragments
126+
.into_iter()
127+
.flat_map(Fragment::into_inner)
128+
.collect();
125129

126130
if flattened.is_empty() {
127131
return;

src/common_traits/clone.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ where
99
{
1010
fn clone(&self) -> Self {
1111
let mut fragments = Vec::with_capacity(self.fragments.capacity());
12-
1312
for fragment in &self.fragments {
14-
let mut vec = Vec::with_capacity(fragment.capacity());
15-
vec.extend_from_slice(fragment);
16-
fragments.push(vec.into());
13+
fragments.push(fragment.clone());
1714
}
18-
1915
Self::from_raw_parts(self.len(), fragments, self.growth().clone())
2016
}
2117
}

src/common_traits/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn are_fragments_eq_to_slice<T: PartialEq>(
7070
for fragment in fragments {
7171
let slice_end = slice_beg + fragment.len();
7272
let slice_of_slice = &slice[slice_beg..slice_end];
73-
if fragment.data != slice_of_slice {
73+
if fragment.as_slice() != slice_of_slice {
7474
return false;
7575
}
7676
slice_beg = slice_end;

src/common_traits/iterator/into_iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<T> IntoIter<T> {
2424
let mut outer = fragments.into_iter();
2525
let inner = outer
2626
.next()
27-
.map(|f| f.data.into_iter())
27+
.map(|f| f.into_iter())
2828
.unwrap_or(Vec::new().into_iter());
2929

3030
Self { outer, inner }
@@ -33,7 +33,7 @@ impl<T> IntoIter<T> {
3333
fn next_fragment(&mut self) -> Option<T> {
3434
match self.outer.next() {
3535
Some(f) => {
36-
self.inner = f.data.into_iter();
36+
self.inner = f.into_iter();
3737
self.next()
3838
}
3939
None => None,

src/common_traits/iterator/iter_ptr.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod tests {
7979

8080
#[test]
8181
fn ptr_one_empty_fragment() {
82-
let fragment: Fragment<String> = Vec::with_capacity(2).into();
82+
let fragment = Fragment::new_empty(2);
8383
let mut fragments: Vec<Fragment<String>> = Vec::with_capacity(4);
8484
fragments.push(fragment);
8585

@@ -91,7 +91,7 @@ mod tests {
9191

9292
#[test]
9393
fn ptr_one_non_empty_fragment() {
94-
let mut fragment: Fragment<String> = Vec::with_capacity(3).into();
94+
let mut fragment = Fragment::new_empty(3);
9595
fragment.push(0.to_string());
9696
fragment.push(1.to_string());
9797

@@ -111,23 +111,23 @@ mod tests {
111111

112112
let prior = 0;
113113
let n = 4;
114-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
114+
let mut fragment = Fragment::new_empty(n);
115115
for i in 0..n {
116116
fragment.push((prior + i).to_string());
117117
}
118118
fragments.push(fragment);
119119

120120
let prior = prior + n;
121121
let n = 8;
122-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
122+
let mut fragment = Fragment::new_empty(n);
123123
for i in 0..n {
124124
fragment.push((prior + i).to_string());
125125
}
126126
fragments.push(fragment);
127127

128128
let prior = prior + n;
129129
let n = 16;
130-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
130+
let mut fragment = Fragment::new_empty(n);
131131
for i in 0..n {
132132
fragment.push((prior + i).to_string());
133133
}
@@ -154,23 +154,23 @@ mod tests {
154154

155155
let prior = 0;
156156
let n = 4;
157-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
157+
let mut fragment = Fragment::new_empty(n);
158158
for i in 0..n {
159159
fragment.push((prior + i).to_string());
160160
}
161161
fragments.push(fragment);
162162

163163
let prior = prior + n;
164164
let n = 8;
165-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
165+
let mut fragment = Fragment::new_empty(n);
166166
for i in 0..n {
167167
fragment.push((prior + i).to_string());
168168
}
169169
fragments.push(fragment);
170170

171171
let prior = prior + n;
172172
let n = 16;
173-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
173+
let mut fragment = Fragment::new_empty(n);
174174
for i in 0..(n / 2) {
175175
fragment.push((prior + i).to_string());
176176
}
@@ -197,23 +197,23 @@ mod tests {
197197

198198
let prior = 0;
199199
let n = 4;
200-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
200+
let mut fragment = Fragment::new_empty(n);
201201
for i in 0..n {
202202
fragment.push((prior + i).to_string());
203203
}
204204
fragments.push(fragment);
205205

206206
let prior = prior + n;
207207
let n = 8;
208-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
208+
let mut fragment = Fragment::new_empty(n);
209209
for i in 0..n {
210210
fragment.push((prior + i).to_string());
211211
}
212212
fragments.push(fragment);
213213

214214
let prior = prior + n;
215215
let n = 16;
216-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
216+
let mut fragment = Fragment::new_empty(n);
217217
for i in 0..(n / 2) {
218218
fragment.push((prior + i).to_string());
219219
}

src/common_traits/iterator/iter_ptr_bwd.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use crate::{
2-
Fragment,
3-
pointers::{PtrBackward, Ptrs},
4-
};
1+
use crate::Fragment;
2+
use crate::pointers::{PtrBackward, Ptrs};
53
use core::iter::FusedIterator;
64

75
#[derive(Copy)]
@@ -79,7 +77,7 @@ mod tests {
7977

8078
#[test]
8179
fn ptr_bwd_one_empty_fragment() {
82-
let fragment: Fragment<String> = Vec::with_capacity(2).into();
80+
let fragment = Fragment::new_empty(2);
8381
let mut fragments: Vec<Fragment<String>> = Vec::with_capacity(4);
8482
fragments.push(fragment);
8583

@@ -91,7 +89,7 @@ mod tests {
9189

9290
#[test]
9391
fn ptr_bwd_one_non_empty_fragment() {
94-
let mut fragment: Fragment<String> = Vec::with_capacity(3).into();
92+
let mut fragment = Fragment::new_empty(3);
9593
fragment.push(0.to_string());
9694
fragment.push(1.to_string());
9795

@@ -111,23 +109,23 @@ mod tests {
111109

112110
let prior = 0;
113111
let n = 4;
114-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
112+
let mut fragment = Fragment::new_empty(n);
115113
for i in 0..n {
116114
fragment.push((prior + i).to_string());
117115
}
118116
fragments.push(fragment);
119117

120118
let prior = prior + n;
121119
let n = 8;
122-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
120+
let mut fragment = Fragment::new_empty(n);
123121
for i in 0..n {
124122
fragment.push((prior + i).to_string());
125123
}
126124
fragments.push(fragment);
127125

128126
let prior = prior + n;
129127
let n = 16;
130-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
128+
let mut fragment = Fragment::new_empty(n);
131129
for i in 0..n {
132130
fragment.push((prior + i).to_string());
133131
}
@@ -154,23 +152,23 @@ mod tests {
154152

155153
let prior = 0;
156154
let n = 4;
157-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
155+
let mut fragment = Fragment::new_empty(n);
158156
for i in 0..n {
159157
fragment.push((prior + i).to_string());
160158
}
161159
fragments.push(fragment);
162160

163161
let prior = prior + n;
164162
let n = 8;
165-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
163+
let mut fragment = Fragment::new_empty(n);
166164
for i in 0..n {
167165
fragment.push((prior + i).to_string());
168166
}
169167
fragments.push(fragment);
170168

171169
let prior = prior + n;
172170
let n = 16;
173-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
171+
let mut fragment = Fragment::new_empty(n);
174172
for i in 0..(n / 2) {
175173
fragment.push((prior + i).to_string());
176174
}
@@ -197,23 +195,23 @@ mod tests {
197195

198196
let prior = 0;
199197
let n = 4;
200-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
198+
let mut fragment = Fragment::new_empty(n);
201199
for i in 0..n {
202200
fragment.push((prior + i).to_string());
203201
}
204202
fragments.push(fragment);
205203

206204
let prior = prior + n;
207205
let n = 8;
208-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
206+
let mut fragment = Fragment::new_empty(n);
209207
for i in 0..n {
210208
fragment.push((prior + i).to_string());
211209
}
212210
fragments.push(fragment);
213211

214212
let prior = prior + n;
215213
let n = 16;
216-
let mut fragment: Fragment<String> = Vec::with_capacity(n).into();
214+
let mut fragment = Fragment::new_empty(n);
217215
for i in 0..(n / 2) {
218216
fragment.push((prior + i).to_string());
219217
}

src/concurrent_iter/con_iter_owned.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use crate::{ParGrowth, SplitVec};
2-
use alloc::vec::Vec;
3-
use orx_concurrent_iter::{
4-
IntoConcurrentIter,
5-
implementations::jagged_arrays::{ConIterJaggedOwned, RawJagged, RawVec},
6-
};
2+
use orx_concurrent_iter::IntoConcurrentIter;
3+
use orx_concurrent_iter::implementations::jagged_arrays::{ConIterJaggedOwned, RawJagged, RawVec};
74

85
impl<T, G> IntoConcurrentIter for SplitVec<T, G>
96
where
@@ -18,7 +15,7 @@ where
1815
let arrays = self
1916
.fragments
2017
.into_iter()
21-
.map(|f| RawVec::from(Vec::from(f)))
18+
.map(|f| RawVec::from(f.into_inner()))
2219
.collect();
2320
let jagged = RawJagged::new(arrays, self.growth, Some(self.len));
2421
jagged.into_con_iter()

0 commit comments

Comments
 (0)