reifydb_core/
delta.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use std::cmp;
5
6use crate::value::encoded::{EncodedKey, EncodedValues};
7
8#[derive(Debug, PartialEq, Eq)]
9pub enum Delta {
10	Set {
11		key: EncodedKey,
12		values: EncodedValues,
13	},
14	Remove {
15		key: EncodedKey,
16	},
17}
18
19impl PartialOrd for Delta {
20	fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
21		Some(self.cmp(other))
22	}
23}
24
25impl Ord for Delta {
26	fn cmp(&self, other: &Self) -> cmp::Ordering {
27		self.key().cmp(other.key())
28	}
29}
30
31impl Delta {
32	/// Returns the key
33	pub fn key(&self) -> &EncodedKey {
34		match self {
35			Self::Set {
36				key,
37				..
38			} => key,
39			Self::Remove {
40				key,
41			} => key,
42		}
43	}
44
45	/// Returns the encoded, if None, it means the entry is marked as remove.
46	pub fn values(&self) -> Option<&EncodedValues> {
47		match self {
48			Self::Set {
49				values: row,
50				..
51			} => Some(row),
52			Self::Remove {
53				..
54			} => None,
55		}
56	}
57}
58
59impl Clone for Delta {
60	fn clone(&self) -> Self {
61		match self {
62			Self::Set {
63				key,
64				values: value,
65			} => Self::Set {
66				key: key.clone(),
67				values: value.clone(),
68			},
69			Self::Remove {
70				key,
71			} => Self::Remove {
72				key: key.clone(),
73			},
74		}
75	}
76}