Skip to main content

reifydb_store_multi/tier/commit/memory/
entry.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use std::{cmp::Reverse, collections::BTreeMap, sync::Arc};
5
6use reifydb_codec::key::encoded::EncodedKey;
7use reifydb_core::{common::CommitVersion, interface::store::EntryKind};
8use reifydb_runtime::sync::{map::Map, rwlock::RwLock};
9use reifydb_value::util::cowvec::CowVec;
10
11pub(super) type Value = Option<CowVec<u8>>;
12
13pub(super) type CurrentMap = BTreeMap<EncodedKey, (CommitVersion, Value)>;
14
15pub(super) type HistoricalMap = BTreeMap<EncodedKey, BTreeMap<Reverse<CommitVersion>, Value>>;
16
17pub(super) struct Entry {
18	pub current: Arc<RwLock<CurrentMap>>,
19
20	pub historical: Arc<RwLock<HistoricalMap>>,
21}
22
23impl Entry {
24	pub fn new() -> Self {
25		Self {
26			current: Arc::new(RwLock::new(BTreeMap::new())),
27			historical: Arc::new(RwLock::new(BTreeMap::new())),
28		}
29	}
30}
31
32impl Clone for Entry {
33	fn clone(&self) -> Self {
34		Self {
35			current: Arc::clone(&self.current),
36			historical: Arc::clone(&self.historical),
37		}
38	}
39}
40
41pub(super) struct Entries {
42	pub(super) data: Map<EntryKind, Entry>,
43}
44
45impl Default for Entries {
46	fn default() -> Self {
47		Self {
48			data: Map::new(),
49		}
50	}
51}