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_core::{common::CommitVersion, encoded::key::EncodedKey, interface::store::EntryKind};
7use reifydb_runtime::sync::{map::Map, rwlock::RwLock};
8use reifydb_value::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) struct Entries {
41	pub(super) data: Map<EntryKind, Entry>,
42}
43
44impl Default for Entries {
45	fn default() -> Self {
46		Self {
47			data: Map::new(),
48		}
49	}
50}