blob: e2921a60f6ce2fa318814d16321ccc47c4d6f347 (
plain)
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
|
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<IndexableValue, LogKey>,
}
impl PrimaryMemtable {
pub fn new() -> PrimaryMemtable {
PrimaryMemtable {
records: BTreeMap::new(),
}
}
pub fn set(&mut self, key: &IndexableValue, value: &LogKey) {
self.records.insert(key.clone(), value.clone());
}
pub fn get(&self, key: &IndexableValue) -> Option<&LogKey> {
self.records.get(key)
}
pub fn remove(&mut self, key: &IndexableValue) -> Option<LogKey> {
self.records.remove(key)
}
pub fn range<B: RangeBounds<IndexableValue>>(&self, range: B) -> Vec<LogKey> {
self.records
.range(range)
.map(|(_, log_key)| log_key.clone())
.collect()
}
}
|