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
84
85
86
87
//! # scry-index
//!
//! A concurrent sorted key-value map backed by learned index structures.
//!
//! This crate provides [`LearnedMap`], a sorted map that uses piecewise linear
//! models to predict key positions, achieving O(1) expected lookup time for
//! keys matching the data distribution. A [`LearnedSet`] wrapper is also
//! available for key-only use cases.
//!
//! # Supported key types
//!
//! Any type implementing [`Key`] can be used. Built-in implementations cover:
//!
//! - Integer types: `u8`..`u128`, `i8`..`i128`
//! - Byte arrays: `[u8; N]` for any `N` (UUIDs, hashes, etc.)
//! - Heap-allocated: `String`, `Vec<u8>`
//!
//! For custom key types with a byte representation, the public helpers
//! [`bytes_to_model_input`] and [`bytes_to_exact_ordinal`] can be used to
//! implement the [`Key`] trait.
//!
//! # Concurrency
//!
//! All operations take `&self` and are safe to call from multiple threads.
//! Reads are lock-free (atomic loads under an epoch guard). Writes use
//! CAS retry loops on individual slots with no global lock.
//!
//! # Algorithm
//!
//! Based on LIPP's chain method: each node contains a linear model
//! `f(key) = slope * key + intercept` that maps keys to unique slots in a
//! fixed-size array. Collisions are resolved by creating child nodes
//! (chaining), not by shifting data. This yields zero prediction error and
//! enables fine-grained concurrent access.
//!
//! # Example
//!
//! ```
//! use scry_index::LearnedMap;
//!
//! let map = LearnedMap::new();
//! let m = map.pin();
//!
//! m.insert(42u64, "hello");
//! m.insert(17u64, "world");
//!
//! assert_eq!(m.get(&42), Some(&"hello"));
//! assert_eq!(m.get(&99), None);
//! assert_eq!(m.len(), 2);
//! ```
//!
//! For pre-sorted data, [`LearnedMap::bulk_load`] builds an optimal tree in
//! one pass:
//!
//! ```
//! use scry_index::LearnedMap;
//!
//! let data: Vec<(u64, &str)> = vec![(1, "a"), (2, "b"), (3, "c")];
//! let map = LearnedMap::bulk_load(&data).unwrap();
//! assert_eq!(map.pin().get(&2), Some(&"b"));
//! ```
//!
//! # Feature flags
//!
//! - **`serde`**: Enables `Serialize`/`Deserialize` for [`LearnedMap`],
//! [`LearnedSet`], [`Config`], and [`Error`].
pub use Config;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;