From 84ac3652415b662aae9580c008a5aa996d58c9f4 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 3 May 2025 00:15:02 +0300 Subject: Rename to AutereDB --- autere_db/src/memtable_primary.rs | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 autere_db/src/memtable_primary.rs (limited to 'autere_db/src/memtable_primary.rs') diff --git a/autere_db/src/memtable_primary.rs b/autere_db/src/memtable_primary.rs new file mode 100644 index 0000000..573592e --- /dev/null +++ b/autere_db/src/memtable_primary.rs @@ -0,0 +1,40 @@ +use super::*; +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, +} + +impl PrimaryMemtable { + pub fn new() -> PrimaryMemtable { + PrimaryMemtable { + records: BTreeMap::new(), + } + } + + pub fn set(&mut self, key: IndexableValue, value: LogKey) { + self.records.insert(key, value); + } + + pub fn get(&self, key: &IndexableValue) -> Option<&LogKey> { + self.records.get(key) + } + + pub fn remove(&mut self, key: &IndexableValue) -> Option { + self.records.remove(key) + } + + pub fn range>(&self, range: B) -> Vec<&LogKey> { + self.records + .range(range) + .map(|(_, log_key)| log_key) + .collect() + } +} -- cgit v1.3