reifydb_store_multi/buffer/memory/
entry.rs1use std::{cmp::Reverse, collections::BTreeMap, sync::Arc};
5
6use reifydb_core::{common::CommitVersion, encoded::key::EncodedKey, interface::store::EntryKind};
7use reifydb_runtime::sync::{map::Map, rwlock::RwLock};
8use reifydb_type::util::cowvec::CowVec;
9
10pub(super) type Value = Option<CowVec<u8>>;
11
12pub(super) type CurrentMap = BTreeMap<EncodedKey, (CommitVersion, Value)>;
13
14pub(super) type HistoricalMap = BTreeMap<EncodedKey, BTreeMap<Reverse<CommitVersion>, Value>>;
15
16pub(super) struct Entry {
17 pub current: Arc<RwLock<CurrentMap>>,
18
19 pub historical: Arc<RwLock<HistoricalMap>>,
20}
21
22impl Entry {
23 pub fn new() -> Self {
24 Self {
25 current: Arc::new(RwLock::new(BTreeMap::new())),
26 historical: Arc::new(RwLock::new(BTreeMap::new())),
27 }
28 }
29}
30
31impl Clone for Entry {
32 fn clone(&self) -> Self {
33 Self {
34 current: Arc::clone(&self.current),
35 historical: Arc::clone(&self.historical),
36 }
37 }
38}
39
40pub(super) fn entry_id_to_key(entry: EntryKind) -> String {
41 match entry {
42 EntryKind::Multi => "multi".to_string(),
43 EntryKind::Source(id) => format!("source:{}", id),
44 EntryKind::Operator(id) => format!("operator:{}", id),
45 }
46}
47
48pub(super) struct Entries {
49 pub(super) data: Map<String, Entry>,
50}
51
52impl Default for Entries {
53 fn default() -> Self {
54 Self {
55 data: Map::new(),
56 }
57 }
58}