noxu_db/database_stats.rs
1//! Per-database statistics.
2//!
3//! Implements `DatabaseStats` (abstract) and `BtreeStats` (concrete).
4
5/// Base statistics type for a database.
6///
7/// Implements abstract `DatabaseStats`. All concrete database stats in
8/// Noxu are represented by [`BtreeStats`].
9#[derive(Clone, Debug, Default)]
10pub struct DatabaseStats {
11 /// B-tree statistics for this database.
12 pub btree: BtreeStats,
13}
14
15impl DatabaseStats {
16 /// Returns the B-tree statistics.
17 pub fn get_btree_stats(&self) -> &BtreeStats {
18 &self.btree
19 }
20}
21
22/// B-tree statistics for a single database.
23///
24/// Returned by [`Database::get_stats`][crate::database::Database::get_stats].
25///
26/// Implements `BtreeStats` with the most commonly used fields:
27///
28/// | Field | |
29/// |-------|--------------|
30/// | `leaf_node_count` | `getLNCount()` |
31/// | `deleted_leaf_node_count` | `getDeletedLNCount()` |
32/// | `bottom_internal_node_count` | `getBottomInternalNodeCount()` |
33/// | `internal_node_count` | `getInternalNodeCount()` |
34/// | `main_tree_max_depth` | `getMainTreeMaxDepth()` |
35#[derive(Clone, Debug, Default)]
36pub struct BtreeStats {
37 /// Total number of leaf-node (LN) records in the tree.
38 /// Equivalent to the approximate record count for the database.
39 pub leaf_node_count: u64,
40 /// Number of known-deleted LN slots not yet compacted.
41 pub deleted_leaf_node_count: u64,
42 /// Number of Bottom Internal Nodes (BINs — leaf-level inner nodes).
43 pub bottom_internal_node_count: u64,
44 /// Number of upper Internal Nodes (INs above BIN level).
45 pub internal_node_count: u64,
46 /// Maximum depth of the main tree (root-to-BIN path length).
47 pub main_tree_max_depth: u32,
48}
49
50impl BtreeStats {
51 /// Returns the total leaf-node record count (approximate).
52 pub fn get_leaf_node_count(&self) -> u64 {
53 self.leaf_node_count
54 }
55
56 /// Returns the count of known-deleted but not yet compacted slots.
57 pub fn get_deleted_leaf_node_count(&self) -> u64 {
58 self.deleted_leaf_node_count
59 }
60
61 /// Returns the number of Bottom Internal Nodes.
62 pub fn get_bottom_internal_node_count(&self) -> u64 {
63 self.bottom_internal_node_count
64 }
65
66 /// Returns the number of upper Internal Nodes.
67 pub fn get_internal_node_count(&self) -> u64 {
68 self.internal_node_count
69 }
70
71 /// Returns the maximum tree depth.
72 pub fn get_main_tree_max_depth(&self) -> u32 {
73 self.main_tree_max_depth
74 }
75}