-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from orxfun/support-for-concurrency
Support for Concurrency
- Loading branch information
Showing
17 changed files
with
944 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "orx-split-vec" | ||
version = "2.6.0" | ||
version = "2.7.0" | ||
edition = "2021" | ||
authors = ["orxfun <[email protected]>"] | ||
description = "An efficient constant access time vector with dynamic capacity and pinned elements." | ||
|
@@ -10,7 +10,7 @@ keywords = ["vec", "array", "split", "fragments", "pinned"] | |
categories = ["data-structures", "rust-patterns"] | ||
|
||
[dependencies] | ||
orx-pinned-vec = "2.5" | ||
orx-pinned-vec = "2.6" | ||
|
||
[[bench]] | ||
name = "serial_access" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,56 @@ | ||
use crate::{Growth, SplitVec}; | ||
use orx_pinned_vec::PinnedVec; | ||
|
||
impl<T, G> Clone for SplitVec<T, G> | ||
where | ||
T: Clone, | ||
G: Growth, | ||
{ | ||
fn clone(&self) -> Self { | ||
let fragments: Vec<_> = self | ||
.fragments | ||
.iter() | ||
.map(|fragment| { | ||
let mut vec = Vec::with_capacity(fragment.capacity()); | ||
vec.extend_from_slice(fragment); | ||
vec.into() | ||
}) | ||
.collect(); | ||
Self { | ||
fragments, | ||
len: self.len, | ||
growth: self.growth.clone(), | ||
let mut fragments = Vec::with_capacity(self.fragments.capacity()); | ||
|
||
for fragment in &self.fragments { | ||
let mut vec = Vec::with_capacity(fragment.capacity()); | ||
vec.extend_from_slice(fragment); | ||
fragments.push(vec.into()); | ||
} | ||
|
||
Self::from_raw_parts(self.len(), fragments, self.growth().clone()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::*; | ||
|
||
#[test] | ||
fn clone() { | ||
fn test<G: Growth>(mut vec: SplitVec<usize, G>) { | ||
for i in 0..168 { | ||
vec.push(i); | ||
} | ||
|
||
let clone = vec.clone(); | ||
|
||
assert_eq!(vec.len(), clone.len()); | ||
assert_eq!(vec.fragments().len(), clone.fragments().len()); | ||
assert_eq!(vec.capacity(), clone.capacity()); | ||
assert_eq!(vec.capacity_state(), clone.capacity_state()); | ||
assert_eq!( | ||
vec.maximum_concurrent_capacity(), | ||
clone.maximum_concurrent_capacity() | ||
); | ||
|
||
for (a, b) in vec.fragments().iter().zip(clone.fragments().iter()) { | ||
assert_eq!(a.len(), b.len()); | ||
assert_eq!(a.capacity(), b.capacity()); | ||
|
||
for (x, y) in a.iter().zip(b.iter()) { | ||
assert_eq!(x, y); | ||
} | ||
} | ||
} | ||
|
||
test_all_growth_types!(test); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.