2 releases
0.1.1 | Nov 22, 2024 |
---|---|
0.1.0 | Nov 21, 2024 |
#941 in Concurrency
308 downloads per month
29KB
544 lines
lockmap
A high-performance, thread-safe HashMap implementation for Rust that provides fine-grained locking at the key level.
Usage
use lockmap::LockMap;
// Create a new lock map
let map = LockMap::new();
// Set a value
map.set("key", "value");
// Get a value
assert_eq!(map.get("key"), Some("value"));
// Use entry API for exclusive access
{
let entry = map.entry("key");
*entry.value = Some("new value");
}
// Remove a value
map.remove("key");
lib.rs
:
A thread-safe hashmap implementation providing per-key level locking and atomic operations.
Overview
lockmap
provides a concurrent hashmap implementation that allows fine-grained locking at the key level.
It uses internal sharding for better performance under high concurrency.
Features
- Thread-safe access with per-key locking
- Entry API for exclusive access to values
- Efficient concurrent operations through sharding
- Safe atomic updates
Examples
use lockmap::LockMap;
let map = LockMap::<String, u32>::new();
// Basic operations
map.set("key1", 42);
assert_eq!(map.get("key1"), Some(42));
// Entry API for exclusive access
{
let entry = map.entry("key2");
entry.value.replace(123);
}
Dependencies
~0–10MB
~43K SLoC