diff --git a/radicle-crdt/src/lwwmap.rs b/radicle-crdt/src/lwwmap.rs index 20bfa24c..dceb0e1b 100644 --- a/radicle-crdt/src/lwwmap.rs +++ b/radicle-crdt/src/lwwmap.rs @@ -10,7 +10,7 @@ pub struct LWWMap { inner: BTreeMap, C>>, } -impl LWWMap { +impl LWWMap { pub fn singleton(key: K, value: V, clock: C) -> Self { Self { inner: BTreeMap::from_iter([(key, LWWReg::new(Some(value), clock))]), @@ -37,10 +37,14 @@ impl LWWMa } pub fn remove(&mut self, key: K, clock: C) { - self.inner - .entry(key) - .and_modify(|reg| reg.set(None, clock)) - .or_insert_with(|| LWWReg::new(None, clock)); + match self.inner.entry(key) { + Entry::Occupied(mut e) => { + e.get_mut().set(None, clock); + } + Entry::Vacant(e) => { + e.insert(LWWReg::new(None, clock)); + } + } } pub fn contains_key(&self, key: K) -> bool {