1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::collections::BTreeMap;
use super::*;
#[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct Meta {
inner: BTreeMap<Vec<u8>, PageId>,
}
impl Meta {
pub fn get_root(&self, table: &[u8]) -> Option<PageId> {
self.inner.get(table).cloned()
}
pub fn set_root(&mut self, name: Vec<u8>, pid: PageId) {
self.inner.insert(name, pid);
}
pub fn del_root(&mut self, name: &[u8]) -> Option<PageId> {
self.inner.remove(name)
}
pub fn tenants(&self) -> BTreeMap<Vec<u8>, PageId> {
self.inner.clone()
}
pub(crate) fn size_in_bytes(&self) -> u64 {
self.inner
.iter()
.map(|(k, _pid)| {
k.len() as u64 + std::mem::size_of::<PageId>() as u64
})
.sum()
}
}