Просмотр исходного кода

Fixed Ordering implementation.

Apparently, from the documentation, if you are going to implement Ord
manually you need to do the same for the rest of the traits.
AvariceLHubris 1 год назад
Родитель
Сommit
baa0d87c9b
1 измененных файлов с 19 добавлено и 2 удалено
  1. 19 2
      src/hufftree/canonical.rs

+ 19 - 2
src/hufftree/canonical.rs

@@ -7,7 +7,7 @@ pub struct CanonicalHufftree {
     characters_and_codes: BiMap<char, BitVec>,
     characters_and_codes: BiMap<char, BitVec>,
 }
 }
 
 
-#[derive(PartialEq, PartialOrd, Eq, Debug)]
+#[derive(Debug)]
 struct CharTempCode {
 struct CharTempCode {
     character: char,
     character: char,
     code: BitVec,
     code: BitVec,
@@ -16,10 +16,25 @@ struct CharTempCode {
 
 
 impl Ord for CharTempCode {
 impl Ord for CharTempCode {
     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-        return self.code_length.cmp(&other.code_length);
+        let ordering = self.code_length.cmp(&other.code_length);
+        ordering
+    }
+}
+
+impl PartialOrd for CharTempCode {
+    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+        Some(self.cmp(other))
     }
     }
 }
 }
 
 
+impl PartialEq for CharTempCode {
+    fn eq(&self, other: &Self) -> bool {
+        return self.code_length == other.code_length;
+    }
+}
+
+impl Eq for CharTempCode {}
+
 impl CanonicalHufftree {
 impl CanonicalHufftree {
     pub fn from_tree(base_tree: Hufftree) -> Self {
     pub fn from_tree(base_tree: Hufftree) -> Self {
         let characters = base_tree.get_characters();
         let characters = base_tree.get_characters();
@@ -37,8 +52,10 @@ impl CanonicalHufftree {
         }
         }
 
 
         character_and_codes.sort();
         character_and_codes.sort();
+        // println!("Ordered characters: {:?}", character_and_codes);
         let mut character_and_codes: Vec<CharTempCode> =
         let mut character_and_codes: Vec<CharTempCode> =
             character_and_codes.into_iter().rev().collect();
             character_and_codes.into_iter().rev().collect();
+        // println!("Ordered characters: {:?}", character_and_codes);
 
 
         let mut first = true;
         let mut first = true;
         let mut prev_length = 0;
         let mut prev_length = 0;