Ver Fonte

Restructure node impl so that the layout makes more sense

AvariceLHubris há 1 ano atrás
pai
commit
aa2628df79
1 ficheiros alterados com 13 adições e 23 exclusões
  1. 13 23
      src/node.rs

+ 13 - 23
src/node.rs

@@ -1,6 +1,6 @@
 use bit_vec::{self, BitVec};
 
-#[derive(Debug)]
+#[derive(Debug, Eq, PartialEq)]
 pub struct Node {
     left: Option<Box<Self>>,
     right: Option<Box<Self>>,
@@ -8,6 +8,18 @@ pub struct Node {
     frequency: i32,
 }
 
+impl Ord for Node {
+    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+        return self.frequency.cmp(&other.frequency)
+    }
+}
+
+impl PartialOrd for Node {
+    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+        return Some(self.frequency.cmp(&other.frequency))
+    }
+}
+
 impl Node {
     pub fn new() -> Node {
         Self {
@@ -111,25 +123,3 @@ mod test {
         assert_eq!(root.get_frequency(), 15);
     }
 }
-
-impl Ord for Node {
-    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-        return self.frequency.cmp(&other.frequency)
-    }
-}
-
-impl PartialOrd for Node {
-    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
-        return Some(self.frequency.cmp(&other.frequency))
-    }
-}
-
-impl Eq for Node {
-
-}
-
-impl PartialEq for Node {
-    fn eq(&self, other: &Self) -> bool {
-        return self.frequency == other.frequency
-    }
-}