From c7c8757959123f524d99e90d3c4f471542e022a0 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Mon, 6 May 2019 13:00:42 +0100 Subject: [PATCH] implemented Ord and PartialOrd for storage::node::Node (#66) --- src/storage/node.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/storage/node.rs b/src/storage/node.rs index 43c0eb8..9297a99 100644 --- a/src/storage/node.rs +++ b/src/storage/node.rs @@ -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` with `hash: Hash`. This requires patching / // rewriting the Blake2b crate to support `.from_bytes()` to serialize from // disk. @@ -115,3 +115,15 @@ impl Display for Node { ) } } + +impl PartialOrd for Node { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.index.cmp(&other.index)) + } +} + +impl Ord for Node { + fn cmp(&self, other: &Self) -> Ordering { + self.index.cmp(&other.index) + } +}