https://github.com/rolag/lockfreehashmap-rs
A concurrent lock-free hash map for Rust.
https://github.com/rolag/lockfreehashmap-rs
concurrent-data-structure hashmap lock-free
Last synced: 10 days ago
JSON representation
A concurrent lock-free hash map for Rust.
- Host: GitHub
- URL: https://github.com/rolag/lockfreehashmap-rs
- Owner: rolag
- License: gpl-3.0
- Archived: true
- Created: 2018-03-16T23:30:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-02-01T00:31:26.000Z (almost 5 years ago)
- Last Synced: 2025-12-13T21:45:21.105Z (26 days ago)
- Topics: concurrent-data-structure, hashmap, lock-free
- Language: Rust
- Size: 882 KB
- Stars: 21
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LockFreeHashMap-rs
[](https://github.com/rolag/lockfreehashmap)
[](https://crates.io/crates/lockfreehashmap)
[](https://docs.rs/lockfreehashmap)
[](https://travis-ci.org/rolag/lockfreehashmap-rs)
A concurrent, lock-free hash map for Rust.
This is an implementation of the lock-free hash map created by Dr. Cliff Click.
Click released a [talk](https://www.youtube.com/watch?v=HJ-719EGIts) about his hash map.
Additionally, "reference" Java code is available
[here](https://github.com/boundary/high-scale-lib/blob/master/src/main/java/org/cliffc/high_scale_lib/NonBlockingHashMap.java)
and more recently
[here](https://github.com/JCTools/JCTools/blob/master/jctools-core/src/main/java/org/jctools/maps/NonBlockingHashMap.java).
## Getting Started
This crate is available on [crates.io](https://crates.io/crates/lockfreehashmap).
To use this crate in your project, add the following to your `Cargo.toml` file:
```toml
[dependencies]
lockfreehashmap = "0.1"
```
and then add to your project root file:
```rust
extern crate lockfreehashmap;
```
## Example
```rust
extern crate lockfreehashmap;
use lockfreehashmap::LockFreeHashMap;
fn main() {
let map = LockFreeHashMap::::new();
let insert_guard = lockfreehashmap::pin();
for i in 1..4 {
map.insert(i, i, &insert_guard);
}
drop(insert_guard);
let map = ↦
lockfreehashmap::scope(|scope| {
// Spawn multiple threads, e.g. for a server that executes some actions on a loop
for _ in 0..16 {
scope.spawn(|| {
loop {
let mut line = String::new();
::std::io::stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
let command: &str = iter.next().unwrap();
let key: u8 = iter.next().unwrap().parse().unwrap();
let value: u8 = iter.next().unwrap().parse().unwrap();
let guard = lockfreehashmap::pin();
let _result = match command {
"insert" => map.insert(key, value, &guard),
_ => unimplemented!(),
};
}
});
}
});
}
```
## Documentation
Documentation is available on [docs.rs](https://docs.rs/lockfreehashmap).
Developer documentation of private types is available [here](https://rolag.github.io/lockfreehashmap-rs/master/lockfreehashmap/).
## Debugging
To use valgrind, add the following lines to the top of the `src/lib.rs` file.
```rust
#![feature(alloc_system, global_allocator, allocator_api)]
extern crate alloc_system;
use alloc_system::System;
#[global_allocator]
static A: System = System;
```
Then call `valgrind --leak-check=full --show-leak-kinds=all ./target/debug/deps/lockfreehashmap-*`
## License
GNU Lesser General Public License v3.0 or any later version
See [LICENSE](LICENSE) and [LICENSE.LESSER](LICENSE.LESSER) for details.