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(
9    feature = "rkyv",
10    derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
11)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct ApproxPos {
14    /// The predicted position of the key.
15    pub pos: usize,
16    /// The lowest index guaranteed to contain the key if it exists.
17    pub lo: usize,
18    /// One past the highest index guaranteed to contain the key if it exists.
19    pub hi: usize,
20}
21
22impl ApproxPos {
23    #[inline]
24    pub fn new(pos: usize, lo: usize, hi: usize) -> Self {
25        Self { pos, lo, hi }
26    }
27}