فهرست منبع

Restructure node impl so that the layout makes more sense

AvariceLHubris 1 سال پیش
والد
کامیت
aa2628df79
1فایلهای تغییر یافته به همراه13 افزوده شده و 23 حذف شده
  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
-    }
-}