Crates.io | moka-cht |
lib.rs | moka-cht |
version | 0.4.2 |
source | src |
created_at | 2021-07-12 13:05:57.146828 |
updated_at | 2021-09-05 15:32:37.958927 |
description | Lock-free resizeable concurrent hash table |
homepage | |
repository | https://github.com/moka-rs/moka-cht |
max_upload_size | |
id | 421893 |
size | 169,531 |
moka-cht provides a lock-free 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. moka-cht also provides a segmented hash table using the same lock-free algorithm for increased concurrent write performance.
Add this to your Cargo.toml
:
moka-cht = "0.5"
Then in your code:
use moka_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| unreachable!());
}
})
})
.collect();
let _: Vec<_> = threads.into_iter().map(|t| t.join()).collect();
moka-cht is distributed under either of
at your option.
See LICENSE-MIT and LICENSE-APACHE for details.
moka-cht is a fork for cht v0.4.1. We have created this fork to provide better integration with Moka cache via a non default Cargo feature.
cht is authored by Gregory Meyer and its v0.4.1 and earlier versions are licensed under the MIT license.