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); } }
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]); } } }
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; }
public HuffmanTree(HuffmanTreeComponent root, List <HuffmanTreeLeaf> symbols) { _root = root; _symbols = symbols; }
public override void SetRight(HuffmanTreeComponent newRight) { _right = newRight; }
public override void SetLeft(HuffmanTreeComponent newLeft) { _left = newLeft; }
public HuffmanTreeNode(HuffmanTreeComponent left, HuffmanTreeComponent right) { _left = left; _right = right; }
public HuffmanTreeNode() { _left = null; _right = null; }