Skip to content

Commit

Permalink
update op ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
iammadab committed Oct 11, 2023
1 parent f948538 commit 04319be
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions grovedb/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 04319be

Please sign in to comment.