Crates.io | cht |
lib.rs | cht |
version | 0.5.0 |
source | src |
created_at | 2019-06-18 01:33:24.824563 |
updated_at | 2021-12-13 05:04:38.698809 |
description | Lockfree resizeable concurrent hash table. |
homepage | |
repository | https://github.com/Gregory-Meyer/cht |
max_upload_size | |
id | 141843 |
size | 146,353 |
cht provides a lockfree hash table that supports fully concurrent lookups, insertions, modifications, and deletions. The table may also be concurrently resized to allow more elements to be inserted. cht also provides a segmented hash table using the same lockfree algorithm for increased concurrent write performance.
In your Cargo.toml
:
cht = "0.5"
Then in your code:
use cht::HashMap;
use std::{sync::Arc, thread};
let map = Arc::new(HashMap::new());
let threads: Vec<_> = (0..16)
.map(|i| {
let map = map.clone();
thread::spawn(move || {
const NUM_INSERTIONS: usize = 64;
for j in (i * NUM_INSERTIONS)..((i + 1) * NUM_INSERTIONS) {
map.insert_and(j, j, |prev| assert_eq!(prev, None));
}
})
})
.collect();
let _: Vec<_> = threads.into_iter().map(|t| t.join()).collect();
cht is licensed under the GNU Affero General Public License v3.0 or later.