示例#1
0
 public void RestrictToLength(int restriction)
 {
     if (ValidateRestriction(restriction))
     {
         Dictionary <int, List <HuffmanTreeComponent> > coinDrawers = InitCoinDrawers(restriction);
         PackageMerge(restriction, coinDrawers);
         Dictionary <HuffmanTreeLeaf, int> codeWordLengths = Evaluate(restriction, coinDrawers);
         _root = CreateLengthLimitedTree(codeWordLengths, restriction);
     }
 }
示例#2
0
        private void RecompositeTree(IReadOnlyDictionary <int, List <HuffmanTreeComponent> > tree)
        {
            List <HuffmanTreeComponent> nodesOfCurrentLevel;

            for (int i = tree.Count - 1; i > 0; i--)
            {
                nodesOfCurrentLevel = tree[i];
                List <HuffmanTreeComponent> nodesOfPreviousLevel = tree[i - 1];
                int finishedNodes = 0;
                for (int j = nodesOfCurrentLevel.Count - 1; j > 0; j = j - 2)
                {
                    HuffmanTreeComponent lastUnusedNode =
                        nodesOfPreviousLevel[nodesOfPreviousLevel.Count - finishedNodes++ - 1];
                    lastUnusedNode.SetLeft(nodesOfCurrentLevel[j - 1]);
                    lastUnusedNode.SetRight(nodesOfCurrentLevel[j]);
                }
            }
        }
示例#3
0
        public void ReplaceMostRight()
        {
            if (_fullBitEliminated)
            {
                return;
            }
            HuffmanTreeComponent currentNode  = _root;
            HuffmanTreeComponent previousNode = _root;

            while (currentNode.GetRight() != null)
            {
                previousNode = currentNode;
                currentNode  = currentNode.GetRight();
            }

            previousNode.SetRight(new HuffmanTreeNode(currentNode, new HuffmanTreeNullLeaf()));
            _symbols.Add(new HuffmanTreeNullLeaf());
            _fullBitEliminated = true;
        }
示例#4
0
 public HuffmanTree(HuffmanTreeComponent root, List <HuffmanTreeLeaf> symbols)
 {
     _root    = root;
     _symbols = symbols;
 }
示例#5
0
 public override void SetRight(HuffmanTreeComponent newRight)
 {
     _right = newRight;
 }
示例#6
0
 public override void SetLeft(HuffmanTreeComponent newLeft)
 {
     _left = newLeft;
 }
示例#7
0
 public HuffmanTreeNode(HuffmanTreeComponent left, HuffmanTreeComponent right)
 {
     _left  = left;
     _right = right;
 }
示例#8
0
 public HuffmanTreeNode()
 {
     _left  = null;
     _right = null;
 }