Skip to content

Commit c7c8757

Browse files
FreddieRidellyoshuawuyts
authored andcommitted
implemented Ord and PartialOrd for storage::node::Node (#66)
1 parent b209cc1 commit c7c8757

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/storage/node.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
33
use flat_tree;
44
use merkle_tree_stream::Node as NodeTrait;
55
use pretty_hash::fmt as pretty_fmt;
6+
use std::cmp::Ordering;
67
use std::convert::AsRef;
78
use std::fmt::{self, Display};
89
use std::io::Cursor;
910

1011
/// Nodes that are persisted to disk.
11-
// TODO: derive Ord, PartialOrd based on index.
1212
// TODO: replace `hash: Vec<u8>` with `hash: Hash`. This requires patching /
1313
// rewriting the Blake2b crate to support `.from_bytes()` to serialize from
1414
// disk.
@@ -115,3 +115,15 @@ impl Display for Node {
115115
)
116116
}
117117
}
118+
119+
impl PartialOrd for Node {
120+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
121+
Some(self.index.cmp(&other.index))
122+
}
123+
}
124+
125+
impl Ord for Node {
126+
fn cmp(&self, other: &Self) -> Ordering {
127+
self.index.cmp(&other.index)
128+
}
129+
}

0 commit comments

Comments
 (0)