Skip to content

Commit 14bb2d2

Browse files
authored
Merge pull request #18 from orxfun/fixed-vec-dependency-is-removed
dependency to orx_fixed_vec
2 parents 5bbbf5f + 175d629 commit 14bb2d2

File tree

3 files changed

+2
-81
lines changed

3 files changed

+2
-81
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "orx-split-vec"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
edition = "2021"
55
authors = ["orxfun <[email protected]>"]
66
description = "An efficient dynamic capacity vector with pinned elements."
@@ -10,7 +10,6 @@ keywords = ["vec", "array", "split", "fragments", "pinned"]
1010
categories = ["data-structures"]
1111

1212
[dependencies]
13-
orx-fixed-vec = "0.4"
1413
orx-pinned-vec = "0.5"
1514

1615

src/fragment/eq.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::{Fragment, Growth, SplitVec};
2-
use orx_fixed_vec::FixedVec;
3-
use orx_pinned_vec::PinnedVec;
1+
use crate::Fragment;
42

53
impl<T: PartialEq, U> PartialEq<U> for Fragment<T>
64
where
@@ -26,9 +24,3 @@ impl<T: PartialEq, const N: usize> PartialEq<Fragment<T>> for [T; N] {
2624
self.as_slice() == other.data
2725
}
2826
}
29-
30-
impl<T: PartialEq, G: Growth> PartialEq<SplitVec<T, G>> for FixedVec<T> {
31-
fn eq(&self, other: &SplitVec<T, G>) -> bool {
32-
self.len() == other.len() && self.iter().zip(other.iter()).all(|(x, y)| x == y)
33-
}
34-
}

src/new_split_vec/into.rs

-70
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{Growth, SplitVec};
2-
use orx_fixed_vec::FixedVec;
32
use orx_pinned_vec::{NotSelfRefVecItem, PinnedVec};
43

54
// std::vec::vec
@@ -79,72 +78,3 @@ where
7978
self.into()
8079
}
8180
}
82-
83-
// orx_fixed_vec::FixedVec
84-
impl<T, G> SplitVec<T, G>
85-
where
86-
G: Growth,
87-
T: NotSelfRefVecItem + Clone,
88-
{
89-
/// Collects the split vector into a fixed vector
90-
/// with a fixed capacity being exactly equal to the length of this split vector.
91-
///
92-
/// # Safety
93-
///
94-
/// Since `T: NotSelfRefVecItem`, it is safe to clone the data of the elements.
95-
///
96-
/// # Examples
97-
///
98-
/// ```
99-
/// use orx_split_vec::prelude::*;
100-
///
101-
/// // SplitVec with dynamic capacity and configurable growth strategy.
102-
/// let mut split = SplitVec::with_linear_growth(5);
103-
/// for i in 0..35 {
104-
/// split.push(i);
105-
/// }
106-
/// assert_eq!(35, split.len());
107-
/// assert_eq!(2, split.fragments().len());
108-
/// assert_eq!(32, split.fragments()[0].len());
109-
/// assert_eq!(3, split.fragments()[1].len());
110-
///
111-
/// // FixedVec with std::vec::Vec complexity & performance.
112-
/// let fixed = split.collect_fixed_vec();
113-
/// assert_eq!(35, fixed.len());
114-
/// assert_eq!(fixed, split);
115-
/// ```
116-
pub fn collect_fixed_vec(&self) -> FixedVec<T> {
117-
unsafe { self.unsafe_collect_fixed_vec() }
118-
}
119-
}
120-
121-
impl<T, G> SplitVec<T, G>
122-
where
123-
G: Growth,
124-
T: Clone,
125-
{
126-
/// Collects the split vector into a fixed vector
127-
/// with a fixed capacity being exactly equal to the length of this split vector.
128-
///
129-
/// # Safety
130-
///
131-
/// Since `T` is not a `NotSelfRefVecItem`, it is assumed as a `SelfRefVecItem`
132-
/// to be conservative. A naive clone of a vector of `SelfRefVecItem` elements
133-
/// is unsafe due to the following scenario:
134-
///
135-
/// * say the vector contains two elements `['a', 'b']` where `'a'` holds a reference to `'b'`.
136-
/// * when we clone this vector, element `'a'` of the second vector will be pointing to
137-
/// element `'b'` of the first vector, which is already incorrect.
138-
/// * furthermore, if the first vector is dropped, the abovementioned reference will be
139-
/// an dangling reference leading to UB.
140-
///
141-
/// Therefore, cloning elements of a vector where elements are not `NotSelfRefVecItem`
142-
/// is `unsafe`.
143-
pub unsafe fn unsafe_collect_fixed_vec(&self) -> FixedVec<T> {
144-
let mut fixed = FixedVec::new(self.len());
145-
for fragment in &self.fragments {
146-
fixed.extend_from_slice(&fragment.data);
147-
}
148-
fixed
149-
}
150-
}

0 commit comments

Comments
 (0)