| Crates.io | lockmap |
| lib.rs | lockmap |
| version | 0.1.14 |
| created_at | 2024-11-21 06:11:42.073079+00 |
| updated_at | 2025-09-04 02:22:43.41787+00 |
| description | A high-performance, thread-safe HashMap implementation for Rust that provides fine-grained locking at the key level. |
| homepage | https://github.com/SF-Zhou/lockmap |
| repository | https://github.com/SF-Zhou/lockmap |
| max_upload_size | |
| id | 1455758 |
| size | 108,070 |
A high-performance, thread-safe HashMap implementation for Rust that provides fine-grained locking at the key level.
use lockmap::LockMap;
// Create a new lock map
let map = LockMap::<String, String>::new();
// Set a value
map.insert_by_ref("key", "value".into());
// Get a value
assert_eq!(map.get("key"), Some("value".into()));
// Use entry API for exclusive access
{
let mut entry = map.entry_by_ref("key");
assert_eq!(entry.get().as_deref(), Some("value"));
entry.insert("new value".to_string());
}
// Remove a value
assert_eq!(map.remove("key"), Some("new value".into()));
// Batch lock.
let mut keys = std::collections::BTreeSet::new();
keys.insert("key1".to_string());
keys.insert("key2".to_string());
let mut locked_entries = map.batch_lock::<std::collections::HashMap<_, _>>(keys);