pgm_extra/util/approx_pos.rs
1/// Approximate position returned by index search.
2///
3/// When searching for a key, the index returns an approximate position
4/// along with guaranteed bounds where the key must exist (if present).
5///
6/// The actual key position (if it exists) is guaranteed to be in `[lo, hi)`.
7#[derive(Clone, Copy, Debug, Default)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct ApproxPos {
10 /// The predicted position of the key.
11 pub pos: usize,
12 /// The lowest index guaranteed to contain the key if it exists.
13 pub lo: usize,
14 /// One past the highest index guaranteed to contain the key if it exists.
15 pub hi: usize,
16}
17
18impl ApproxPos {
19 #[inline]
20 pub fn new(pos: usize, lo: usize, hi: usize) -> Self {
21 Self { pos, lo, hi }
22 }
23}