#hash-map #locking #level #thread-safe #key #sharding #key-value

lockmap

A high-performance, thread-safe HashMap implementation for Rust that provides fine-grained locking at the key level

1 unstable release

new 0.1.0 Nov 21, 2024

#5 in #sharding

MIT/Apache

29KB
540 lines

lockmap

Rust codecov Crates.io Documentation

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