aboutsummaryrefslogtreecommitdiff
path: root/src/util/crdt/lww_map.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-12-14 13:55:11 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-04 12:45:46 +0100
commit5b1117e582db16cc5aa50840a685875cbd5501f4 (patch)
tree06fec47bf56cb08cb51334454dc15f98352c98f2 /src/util/crdt/lww_map.rs
parent8f6026de5ecd44cbe0fc0bcd47638a1ece860439 (diff)
downloadgarage-5b1117e582db16cc5aa50840a685875cbd5501f4.tar.gz
garage-5b1117e582db16cc5aa50840a685875cbd5501f4.zip
New model for buckets
Diffstat (limited to 'src/util/crdt/lww_map.rs')
-rw-r--r--src/util/crdt/lww_map.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/util/crdt/lww_map.rs b/src/util/crdt/lww_map.rs
index 3e9aba79..21cb6e12 100644
--- a/src/util/crdt/lww_map.rs
+++ b/src/util/crdt/lww_map.rs
@@ -30,8 +30,8 @@ pub struct LwwMap<K, V> {
impl<K, V> LwwMap<K, V>
where
- K: Ord,
- V: Crdt,
+ K: Clone + Ord,
+ V: Clone + Crdt,
{
/// Create a new empty map CRDT
pub fn new() -> Self {
@@ -73,6 +73,10 @@ where
};
Self { vals: new_vals }
}
+
+ pub fn update_in_place(&mut self, k: K, new_v: V) {
+ self.merge(&self.update_mutator(k, new_v));
+ }
/// Takes all of the values of the map and returns them. The current map is reset to the
/// empty map. This is very usefull to produce in-place a new map that contains only a delta
/// that modifies a certain value:
@@ -158,8 +162,8 @@ where
impl<K, V> Default for LwwMap<K, V>
where
- K: Ord,
- V: Crdt,
+ K: Clone + Ord,
+ V: Clone + Crdt,
{
fn default() -> Self {
Self::new()