nut/bucket/
stats.rs

1use std::ops::AddAssign;
2
3#[derive(Default, Debug)]
4/// Records statistics about resources used by a bucket.
5pub struct BucketStats {
6    // Page count statistics.
7    pub branch_page_n: usize,     // number of logical branch pages
8    pub branch_overflow_n: usize, // number of physical branch overflow pages
9    pub leaf_page_n: usize,       // number of logical leaf pages
10    pub leaf_overflow_n: usize,   // number of physical leaf overflow pages
11
12    // Tree statistics.
13    pub key_n: usize, // number of keys/value pairs
14    pub depth: usize, // number of levels in B+tree
15
16    // Page size utilization.
17    pub branch_alloc: usize,  // bytes allocated for physical branch pages
18    pub branch_in_use: usize, // bytes actually used for branch data
19    pub leaf_alloc: usize,    // bytes allocated for physical leaf pages
20    pub leaf_in_use: usize,   // bytes actually used for leaf data
21
22    // Bucket statistics
23    pub bucket_n: usize, // total number of buckets including the top bucket
24    pub inline_bucket_n: usize, // total number on inlined buckets
25    pub inline_bucket_in_use: usize, // bytes used for inlined buckets (also accounted for in LeafInuse)
26}
27
28impl AddAssign for BucketStats {
29    fn add_assign(&mut self, other: BucketStats) {
30        self.branch_page_n += other.branch_page_n;
31        self.branch_overflow_n += other.branch_overflow_n;
32        self.leaf_page_n += other.leaf_page_n;
33        self.leaf_overflow_n += other.leaf_overflow_n;
34        self.key_n += other.key_n;
35        if self.depth < other.depth {
36            self.depth = other.depth;
37        };
38        self.branch_alloc += other.branch_alloc;
39        self.branch_in_use += other.branch_in_use;
40        self.leaf_alloc += other.leaf_alloc;
41        self.leaf_in_use += other.leaf_in_use;
42
43        self.bucket_n += other.bucket_n;
44        self.inline_bucket_n += other.inline_bucket_n;
45        self.inline_bucket_in_use += other.inline_bucket_in_use;
46    }
47}