diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-11-02 16:58:01 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-11-02 17:39:22 +0200 |
| commit | 912c32f762ee7585e20fde57c7c5dca1f9b0478d (patch) | |
| tree | afad7b189adb3a5189174e1fd9b44823cf63b3fa /log_db/src/memtable_primary.rs | |
| parent | 3838cd9ee68ff5433f00a52feed04a9682b79161 (diff) | |
Refactor in preparation to larger changes
Diffstat (limited to 'log_db/src/memtable_primary.rs')
| -rw-r--r-- | log_db/src/memtable_primary.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/log_db/src/memtable_primary.rs b/log_db/src/memtable_primary.rs new file mode 100644 index 0000000..9d7e1e8 --- /dev/null +++ b/log_db/src/memtable_primary.rs @@ -0,0 +1,33 @@ +use super::common::*; +use std::collections::BTreeMap; + +pub struct PrimaryMemtable { + /// Map of records indexed by key. Used as a shared heap of records + /// for all secondary memtables also. Secondary memtables store an + /// IndexableValue as their record value, which is used to get + /// the actual record from the primary memtable `records` map. + /// + /// Note: it must be invariant that all memtables (primary and secondary) + /// contain the same keys. + records: BTreeMap<IndexableValue, Record>, +} + +impl PrimaryMemtable { + pub fn new() -> PrimaryMemtable { + PrimaryMemtable { + records: BTreeMap::new(), + } + } + + pub fn set(&mut self, key: &IndexableValue, value: &Record) { + self.records.insert(key.clone(), value.clone()); + } + + pub fn get(&mut self, key: &IndexableValue) -> Option<&Record> { + self.records.get(key) + } + + pub fn get_without_update(&self, key: &IndexableValue) -> Option<&Record> { + self.records.get(key) + } +} |
