8 releases (4 breaking)

0.5.0 Dec 13, 2021
0.4.1 Mar 11, 2020
0.3.0 Mar 5, 2020
0.2.0 Feb 28, 2020
0.1.2 Jun 26, 2019

#484 in Concurrency

Download history 82/week @ 2024-01-04 22/week @ 2024-01-11 6/week @ 2024-01-18 1/week @ 2024-01-25 2/week @ 2024-02-01 3/week @ 2024-02-08 15/week @ 2024-02-15 32/week @ 2024-02-22 77/week @ 2024-02-29 76/week @ 2024-03-07 84/week @ 2024-03-14 76/week @ 2024-03-21 84/week @ 2024-03-28 81/week @ 2024-04-04 83/week @ 2024-04-11 58/week @ 2024-04-18

315 downloads per month

AGPL-3.0-or-later

115KB
2K 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.5"

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 GNU Affero General Public License v3.0 or later.

Dependencies

~260KB