From 6e946239c514dedcfa97eb1a42792790d38cb3eb Mon Sep 17 00:00:00 2001 From: Wisdom Ogwu <40731160+iammadab@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:31:34 +0100 Subject: [PATCH] fix: op ord implemenation (#275) * update op ordering * fix comment * do fixed ordering, remove equality * fmt --- grovedb/src/batch/mod.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/grovedb/src/batch/mod.rs b/grovedb/src/batch/mod.rs index 9724ea7b..8f275095 100644 --- a/grovedb/src/batch/mod.rs +++ b/grovedb/src/batch/mod.rs @@ -166,6 +166,22 @@ pub enum Op { DeleteSumTree, } +impl Op { + fn to_u8(&self) -> u8 { + match self { + Op::DeleteTree => 0, + Op::DeleteSumTree => 1, + Op::Delete => 2, + Op::InsertTreeWithRootHash { .. } => 3, + Op::ReplaceTreeRootKey { .. } => 4, + Op::RefreshReference { .. } => 5, + Op::Replace { .. } => 6, + Op::Patch { .. } => 7, + Op::Insert { .. } => 8, + } + } +} + impl PartialOrd for Op { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) @@ -174,13 +190,7 @@ 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, - _ => Ordering::Equal, - } + self.to_u8().cmp(&other.to_u8()) } }