Skip to content

Commit b69131a

Browse files
hcplAmanieu
authored andcommitted
Add Rayon support
The code is adapted from `rayon-hash`.
1 parent 3f26a98 commit b69131a

File tree

13 files changed

+2441
-200
lines changed

13 files changed

+2441
-200
lines changed

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ keywords = ["hash", "no_std", "hashmap", "swisstable"]
1010
categories = ["data-structures", "no-std"]
1111

1212
[dependencies]
13-
scopeguard = { version = "0.3", default-features = false }
1413
byteorder = { version = "1.0", default-features = false }
14+
scopeguard = { version = "0.3", default-features = false }
15+
16+
# For external trait impls
17+
rayon = { version = "1.0", optional = true }
1518
serde = { version = "1.0", default-features = false, optional = true }
1619

1720
[dev-dependencies]
21+
lazy_static = "~1.2"
22+
rand = "0.5.1"
23+
rayon = "1.0"
1824
rustc-hash = "1.0"
1925
serde_test = "1.0"
20-
rand = "0.5.1"
2126

2227
[features]
2328
nightly = []

src/external_trait_impls/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg(feature = "rayon")]
2+
pub(crate) mod rayon;
3+
#[cfg(feature = "serde")]
4+
mod serde;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use alloc::collections::LinkedList;
2+
use alloc::vec::Vec;
3+
4+
use rayon::iter::{IntoParallelIterator, ParallelIterator};
5+
6+
7+
/// Helper for collecting parallel iterators to an intermediary
8+
pub(super) fn collect<I: IntoParallelIterator>(iter: I) -> (LinkedList<Vec<I::Item>>, usize) {
9+
let list = iter
10+
.into_par_iter()
11+
.fold(Vec::new, |mut vec, elem| {
12+
vec.push(elem);
13+
vec
14+
}).map(|vec| {
15+
let mut list = LinkedList::new();
16+
list.push_back(vec);
17+
list
18+
}).reduce(LinkedList::new, |mut list1, mut list2| {
19+
list1.append(&mut list2);
20+
list1
21+
});
22+
23+
let len = list.iter().map(Vec::len).sum();
24+
(list, len)
25+
}

0 commit comments

Comments
 (0)