Skip to content

Commit 2b8cead

Browse files
committed
fix: implement Ord for BranchKey
1 parent f080153 commit 2b8cead

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/tree.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
vec::Vec,
77
H256, MAX_STACK_SIZE,
88
};
9+
use core::cmp::Ordering;
910
use core::marker::PhantomData;
1011

1112
/// The branch key
@@ -21,6 +22,20 @@ impl BranchKey {
2122
}
2223
}
2324

25+
impl PartialOrd for BranchKey {
26+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
27+
Some(self.cmp(other))
28+
}
29+
}
30+
impl Ord for BranchKey {
31+
fn cmp(&self, other: &Self) -> Ordering {
32+
match self.height.cmp(&other.height) {
33+
Ordering::Equal => self.node_key.cmp(&other.node_key),
34+
ordering => ordering,
35+
}
36+
}
37+
}
38+
2439
/// A branch in the SMT
2540
#[derive(Debug, Eq, PartialEq, Clone)]
2641
pub struct BranchNode {

0 commit comments

Comments
 (0)