Esempio n. 1
0
        public static HuffmanTree Build(TreeNodeTraits nodeTraits)
        {
            Guard.IsNotNull(nodeTraits, nameof(nodeTraits));
            TreeNodeTraits rootTraits = GetRoot(nodeTraits);

            return(new HuffmanTree(DoBuild(rootTraits)));
        }
Esempio n. 2
0
        static TreeNodeTraits GetRoot(TreeNodeTraits nodeTraits)
        {
            TreeNodeTraits root = nodeTraits;

            while (root.Parent != null)
            {
                root = root.Parent;
            }
            return(root);
        }
Esempio n. 3
0
        static HuffmanTreeNode DoBuild(TreeNodeTraits nodeTraits)
        {
            if (nodeTraits == null)
            {
                return(null);
            }

            HuffmanTreeNode l = DoBuild(nodeTraits.Left);
            HuffmanTreeNode r = DoBuild(nodeTraits.Right);

            return(new HuffmanTreeNode(nodeTraits.Symbol, l, r));
        }
Esempio n. 4
0
 public TreeNodeTraits NewNode(int weight, byte?symbol)
 {
     return(TreeNodeTraits.New(weight, symbol));
 }
Esempio n. 5
0
 public TreeNodeTraits NewNode(int weight, char?symbol)
 {
     return(TreeNodeTraits.New(weight, (byte?)symbol));
 }