7 unstable releases (3 breaking)

✓ Uses Rust 2018 edition

0.4.1 Mar 11, 2020
0.4.0 Mar 10, 2020
0.3.0 Mar 5, 2020
0.2.0 Feb 28, 2020
0.1.2 Jun 26, 2019

#73 in Concurrency

Download history 36/week @ 2019-12-10 17/week @ 2019-12-17 5/week @ 2019-12-24 66/week @ 2019-12-31 7/week @ 2020-01-07 107/week @ 2020-01-14 44/week @ 2020-01-21 56/week @ 2020-01-28 20/week @ 2020-02-04 21/week @ 2020-02-11 16/week @ 2020-02-18 32/week @ 2020-02-25 31/week @ 2020-03-03 59/week @ 2020-03-10 29/week @ 2020-03-17 45/week @ 2020-03-24

159 downloads per month
Used in dashmap

MIT license

155KB
2.5K SLoC

cht

crates.io docs.rs Travis CI

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.

Usage

In your Cargo.toml:

cht = "^0.4.1"

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();

License

cht is licensed under the MIT license.

Dependencies

~350KB