cht provides a lockfree hash table that supports concurrent lookups, insertions, and deletions.
In your Cargo.toml
:
toml
cht = "^0.3.0"
Then in your code:
```rust 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.intoiter().map(|t| t.join()).collect(); ```
cht is licensed under the MIT license.