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
// ALEX is a numeric algorithm with inherent precision tradeoffs
//! ALEX: Adaptive Learned Index
//!
//! A production-ready implementation of the ALEX learned index structure
//! from Microsoft Research.
//!
//! ALEX (Adaptive Learned indEX) combines machine learning models with
//! traditional indexing techniques to provide fast lookups, inserts, updates,
//! and deletes. Unlike static learned indexes (RMI), ALEX supports dynamic
//! workloads through:
//!
//! 1. **Gapped Arrays**: Leaf nodes maintain spare capacity for future inserts
//! 2. **Local Node Splitting**: When nodes fill, split locally instead of rebuilding entire tree
//! 3. **Adaptive Models**: Models adapt to data distribution changes
//!
//! ## Performance Characteristics
//!
//! - **Lookups**: O(log n) with learned index acceleration → practical O(1) to O(log log n)
//! - **Inserts**: O(log n) amortized (O(1) into gapped array + occasional splits)
//! - **Deletes**: O(log n) with lazy deletion
//! - **Space**: O(n) with tunable expansion factor (1.0 = 50% overhead by default)
//!
//! ## References
//!
//! - ALEX Paper: <https://www.microsoft.com/en-us/research/uploads/prod/2020/04/MSRAlexTechnicalReportV2.pdf>
//! - GitHub: <https://github.com/microsoft/ALEX>
//!
//! ## Example Usage
//!
//! ```rust,ignore
//! use seerdb::alex::AlexTree;
//!
//! let mut index = AlexTree::new();
//!
//! // Insert key-value pairs
//! index.insert(10, vec![1, 2, 3])?;
//! index.insert(20, vec![4, 5, 6])?;
//! index.insert(15, vec![7, 8, 9])?; // Out of order - ALEX handles it
//!
//! // Lookup
//! if let Some(value) = index.get(15)? {
//! println!("Found: {:?}", value);
//! }
//!
//! // Range query
//! for (key, value) in index.range(10..=20)? {
//! println!("{}: {:?}", key, value);
//! }
//! ```
// Fallback for non-SIMD builds
// Re-exports
pub use AlexTree;
pub use GappedNode;
pub use LinearModel;
pub use MultiLevelAlexTree;