kevy_index/segment_stats.rs
1//! [`SegmentStats`] — the sizing and health counters a [`crate::Segment`]
2//! reports.
3
4/// Sizing + health counters (`IDX.LIST` / memory formula).
5///
6/// ```
7/// use kevy_index::{Segment, SegmentStats};
8/// let s = Segment::new().stats();
9/// assert_eq!((s.entries, s.duplicates), (0, SegmentStats::default().duplicates));
10/// ```
11#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
12#[non_exhaustive]
13pub struct SegmentStats {
14 /// Live entries.
15 ///
16 /// ```
17 /// # use kevy_index::{IndexValue, Segment};
18 /// let mut s = Segment::new();
19 /// s.apply(b"a", None, Some(IndexValue::I64(1)));
20 /// s.apply(b"a", Some(&IndexValue::I64(1)), Some(IndexValue::I64(2)));
21 /// assert_eq!(s.stats().entries, 1, "a key holds one entry");
22 /// ```
23 pub entries: u64,
24 /// Approximate heap bytes (the measured side of the documented
25 /// memory formula).
26 ///
27 /// ```
28 /// # use kevy_index::{IndexValue, Segment};
29 /// let mut s = Segment::new();
30 /// s.apply(b"a", None, Some(IndexValue::Str(vec![b'x'; 1000])));
31 /// assert!(s.stats().approx_bytes >= 1000);
32 /// ```
33 pub approx_bytes: u64,
34 /// Rows excluded because the field failed coercion / was missing.
35 ///
36 /// ```
37 /// # use kevy_index::{Segment, ValType, IndexValue};
38 /// let mut s = Segment::new();
39 /// s.apply(b"a", None, IndexValue::coerce(ValType::I64, b"not a number"));
40 /// assert_eq!(s.stats().coerce_failures, 1);
41 /// ```
42 pub coerce_failures: u64,
43 /// Values currently held by more than one key (unique fence).
44 ///
45 /// ```
46 /// # use kevy_index::{IndexValue, Segment};
47 /// let mut s = Segment::new();
48 /// s.apply(b"a", None, Some(IndexValue::I64(7)));
49 /// s.apply(b"b", None, Some(IndexValue::I64(7)));
50 /// assert_eq!(s.stats().duplicates, 1);
51 /// ```
52 pub duplicates: u64,
53}