#hashmap #concurrent

moka-cht

Lock-free resizeable concurrent hash table

2 unstable releases

0.5.0 Jul 12, 2021
0.4.2 Sep 5, 2021

#242 in Data structures

Download history 1095/week @ 2021-08-17 982/week @ 2021-08-24 723/week @ 2021-08-31 1869/week @ 2021-09-07 976/week @ 2021-09-14 598/week @ 2021-09-21 857/week @ 2021-09-28 1087/week @ 2021-10-05 1458/week @ 2021-10-12 906/week @ 2021-10-19 1099/week @ 2021-10-26 1254/week @ 2021-11-02 638/week @ 2021-11-09 548/week @ 2021-11-16 743/week @ 2021-11-23 650/week @ 2021-11-30

2,814 downloads per month
Used in 11 crates (via moka)

MIT/Apache

150KB
3K SLoC

moka-cht

GitHub Actions crates.io release docs dependency status license

moka-cht provides a lock-free 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. moka-cht also provides a segmented hash table using the same lock-free algorithm for increased concurrent write performance.

Usage

Add this to your Cargo.toml:

moka-cht = "0.5"

Then in your code:

use moka_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| unreachable!());
            }
        })
    })
    .collect();

let _: Vec<_> = threads.into_iter().map(|t| t.join()).collect();

License

moka-cht is distributed under either of

  • The MIT license
  • The Apache License (Version 2.0)

at your option.

See LICENSE-MIT and LICENSE-APACHE for details.

Credits

moka-cht is a fork for cht v0.4.1. We have created this fork to provide better integration with Moka cache via a non default Cargo feature.

cht is authored by Gregory Meyer and its v0.4.1 and earlier versions are licensed under the MIT license.

Dependencies

~335KB

4a