7 unstable releases (3 breaking)

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

#236 in Concurrency

Download history 49/week @ 2021-06-21 56/week @ 2021-06-28 51/week @ 2021-07-05 57/week @ 2021-07-12 77/week @ 2021-07-19 83/week @ 2021-07-26 99/week @ 2021-08-02 70/week @ 2021-08-09 28/week @ 2021-08-16 82/week @ 2021-08-23 8/week @ 2021-08-30 25/week @ 2021-09-06 27/week @ 2021-09-13 145/week @ 2021-09-20 155/week @ 2021-09-27 18/week @ 2021-10-04

234 downloads per month

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

~480KB