Пример #1
0
 /// <summary> returns bool, whether node1 <= node2 </summary>
 private static bool NodeCompare(HuffmannTree node1, HuffmannTree node2)
 {
     if (node1.Weight != node2.Weight)
     {
         return(node1.Weight < node2.Weight);
     }
     else
     {
         if (node1.IsLeaf() && node2.IsLeaf())
         {
             return(node1.Symbol <= node2.Symbol);
         }
         else if (node1.IsLeaf() && !node2.IsLeaf())
         {
             // leaves are lighter then inner nodes
             return(true);
         }
         else if (!node1.IsLeaf() && node2.IsLeaf())
         {
             return(false);
         }
         else
         {
             // two inner nodes with the same Weight
             return(true);
         }
     }
 }
Пример #2
0
 void BuildPathsDictionary(HuffmannTree node, List <byte> path)
 {
     if (node.IsLeaf())
     {
         paths.Add((char)node.Symbol, path.ToArray());
     }
     else
     {
         path.Add(0);
         BuildPathsDictionary(node.Left, path);
         path.RemoveAt(path.Count - 1);
         path.Add(1);
         BuildPathsDictionary(node.Right, path);
         path.RemoveAt(path.Count - 1);
     }
 }