8个版本 (4个重大变更)
0.5.0 | 2021年12月13日 |
---|---|
0.4.1 | 2020年3月11日 |
0.3.0 | 2020年3月5日 |
0.2.0 | 2020年2月28日 |
0.1.2 | 2019年6月26日 |
#527 在 并发
每月321 次下载
115KB
2K SLoC
cht
cht 提供了一个无锁哈希表,支持完全并发的查找、插入、修改和删除。该表还可以并发地调整大小,以允许插入更多元素。cht 还提供了一种使用相同无锁算法的段式哈希表,以提高并发写性能。
用法
在你的 Cargo.toml
cht = "0.5"
然后在你的代码中
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 采用 GNU Affero 通用公共许可证 v3.0 或更高版本授权。
依赖项
~255KB