lock_free/lib.rs
1#![warn(missing_docs)]
2#![deny(unsafe_op_in_unsafe_fn)]
3
4//! A collection of high-performance lock-free data structures for Rust.
5//!
6//! This crate provides thread-safe, lock-free implementations of common
7//! data structures that can be used in concurrent environments without
8//! the overhead of traditional locking mechanisms.
9//!
10//! ## Performance
11//! - Stack: 24M+ ops/sec
12//! - Queue: 25M+ ops/sec
13//! - List: 3M+ ops/sec (O(log n) skip list)
14//! - HashMap: 10-30M+ ops/sec (scales with threads)
15//!
16//! ## Example
17//! ```ignore
18//! use lock_free::{Stack, Queue, List, HashMap};
19//!
20//! // High-performance stack
21//! let stack = Stack::new();
22//! stack.push(42);
23//! assert_eq!(stack.pop(), Some(42));
24//!
25//! // Fast bounded queue
26//! let queue = Queue::new(1024);
27//! queue.enqueue("hello");
28//! assert_eq!(queue.dequeue(), Some("hello"));
29//!
30//! // Ordered key-value list
31//! let list = List::new();
32//! list.insert("key", "value");
33//! assert!(list.contains(&"key"));
34//!
35//! // Fast concurrent hashmap
36//! let map = HashMap::new();
37//! map.insert("key", "value");
38//! assert_eq!(map.get(&"key"), Some("value"));
39//! ```
40
41// Internal modules - best implementations
42mod stack;
43pub mod skiplist;
44pub mod skiplist_fast;
45mod queue_bounded;
46pub mod hashmap_fast;
47pub mod hashmap_ultra;
48pub mod list_o1;
49
50// Additional modules for variants
51mod list;
52mod queue;
53mod stack_optimized;
54mod queue_lcrq;
55mod queue_faa;
56
57// Public API - Simple, clean names for the best implementations
58pub use stack::Stack;
59pub use skiplist_fast::FastSkipList as List;
60pub use queue_bounded::BoundedQueue as Queue;
61pub use hashmap_ultra::UltraHashMap as HashMap;
62
63// Re-export original BoundedQueue for those who need the specific type
64pub use queue_bounded::BoundedQueue;
65
66// Optional variants module for specialized use cases
67pub mod variants {
68 //! Alternative implementations for specific use cases.
69 //!
70 //! Most users should use the main `Stack`, `Queue`, and `List` types.
71 //! These variants are provided for special requirements.
72
73 /// Original O(n) linked list - only use for small collections (<100 items)
74 pub use crate::list::List as SimpleList;
75
76 /// Unbounded Michael & Scott queue - use when you can't specify a capacity
77 pub use crate::queue::Queue as UnboundedQueue;
78
79 /// Stack with hazard pointers - use if you need guaranteed memory reclamation
80 pub use crate::stack_optimized::Stack as HazardStack;
81
82 /// Alternative queue implementations
83 pub use crate::queue_faa::FAAQueue;
84 pub use crate::queue_lcrq::LCRQ;
85}
86
87/// Collection utilities
88pub mod collections;