From 264197eba3420028c328f272618691e7f5769817 Mon Sep 17 00:00:00 2001 From: Wisdom Ogwu Date: Wed, 11 Oct 2023 15:10:39 +0100 Subject: [PATCH] update op ordering --- grovedb/src/batch/mod.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index 9724ea7b..a833a4da 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -175,10 +175,22 @@ impl PartialOrd for Op { impl Ord for Op { fn cmp(&self, other: &Self) -> Ordering { match (self, other) { - (Op::Delete, Op::Insert { .. }) => Ordering::Less, - (Op::Delete, Op::Replace { .. }) => Ordering::Less, - (Op::Insert { .. }, Op::Delete) => Ordering::Greater, - (Op::Replace { .. }, Op::Delete) => Ordering::Greater, + // deal with relationship between delete ops + (Op::DeleteTree, Op::DeleteSumTree) | (Op::DeleteSumTree, Op::DeleteTree) => { + Ordering::Equal + } + (Op::DeleteTree, Op::Delete) => Ordering::Less, + (Op::Delete, Op::DeleteTree) => Ordering::Greater, + (Op::DeleteSumTree, Op::Delete) => Ordering::Less, + (Op::Delete, Op::DeleteSumTree) => Ordering::Greater, + + // deal with the relationship between delete and other ops + // delete should always happen first + (Op::Delete, _) => Ordering::Less, + (Op::DeleteSumTree, _) => Ordering::Less, + (Op::DeleteTree, _) => Ordering::Less, + + // all insert operations are considered equal _ => Ordering::Equal, } }