Skip to content

Commit

Permalink
implemented Ord and PartialOrd for storage::node::Node (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddieRidell authored and yoshuawuyts committed May 6, 2019
1 parent b209cc1 commit c7c8757
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/storage/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use flat_tree;
use merkle_tree_stream::Node as NodeTrait;
use pretty_hash::fmt as pretty_fmt;
use std::cmp::Ordering;
use std::convert::AsRef;
use std::fmt::{self, Display};
use std::io::Cursor;

/// Nodes that are persisted to disk.
// TODO: derive Ord, PartialOrd based on index.
// TODO: replace `hash: Vec<u8>` with `hash: Hash`. This requires patching /
// rewriting the Blake2b crate to support `.from_bytes()` to serialize from
// disk.
Expand Down Expand Up @@ -115,3 +115,15 @@ impl Display for Node {
)
}
}

impl PartialOrd for Node {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.index.cmp(&other.index))
}
}

impl Ord for Node {
fn cmp(&self, other: &Self) -> Ordering {
self.index.cmp(&other.index)
}
}

0 comments on commit c7c8757

Please sign in to comment.