Skip to content

Commit

Permalink
fix: op ord implemenation (#275)
Browse files Browse the repository at this point in the history
* update op ordering

* fix comment

* do fixed ordering, remove equality

* fmt
  • Loading branch information
iammadab authored Oct 11, 2023
1 parent f948538 commit 6e94623
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions grovedb/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ordering> {
Some(self.cmp(other))
Expand All @@ -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())
}
}

Expand Down

0 comments on commit 6e94623

Please sign in to comment.