1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! # Elastic Hash Map
//!
//! A Rust implementation of a hash table with adaptive probing strategy.
//!
//! This crate provides two hash map implementations:
//!
//! - `ElasticHashMap`: A single-threaded implementation optimized for performance
//! - `ConcurrentElasticMap`: A lock-free, thread-safe implementation for concurrent access
//!
//! Both implementations use an adaptive probing strategy that dynamically adjusts step
//! sizes based on observed occupancy patterns, resulting in more efficient lookups.
//!
//! ## Basic Usage
//!
//! ```rust
//! use bathroom::ElasticHashMap;
//!
//! // Create a new hash map
//! let mut map = ElasticHashMap::new();
//!
//! // Insert values
//! map.insert("apple".to_string(), 1);
//! map.insert("banana".to_string(), 2);
//!
//! // Retrieve values
//! assert_eq!(map.get("apple"), Some(&1));
//!
//! // Update values
//! map.insert("apple".to_string(), 10);
//! assert_eq!(map.get("apple"), Some(&10));
//!
//! // Remove values
//! map.remove("apple");
//! assert_eq!(map.get("apple"), None);
//! ```
//!
//! ## Concurrent Usage
//!
//! ```rust
//! use bathroom::ConcurrentElasticMap;
//! use std::sync::Arc;
//! use std::thread;
//!
//! // Create a shared hash map
//! let map = Arc::new(ConcurrentElasticMap::new());
//!
//! // Clone references for different threads
//! let map1 = Arc::clone(&map);
//! let map2 = Arc::clone(&map);
//!
//! // Spawn threads that modify the map concurrently
//! let t1 = thread::spawn(move || {
//! for i in 0..100 {
//! map1.insert(format!("key-{}", i), i);
//! }
//! });
//!
//! let t2 = thread::spawn(move || {
//! for i in 100..200 {
//! map2.insert(format!("key-{}", i), i);
//! }
//! });
//!
//! // Wait for threads to complete
//! t1.join().unwrap();
//! t2.join().unwrap();
//!
//! // Due to potential race conditions in a concurrent environment,
//! // the final count might be slightly less than expected
//! let count = map.len();
//! assert!(count >= 190, "Expected at least 190 entries, found {}", count);
//! ```
/// Module implementing a thread-safe concurrent hash map with elastic probing
/// Module implementing a single-threaded hash map with elastic probing
/// Utility functions and traits for the hash maps
pub use ConcurrentElasticMap;
pub use ElasticHashMap;
pub use HashMapExtensions;