Пример #1
0
        private void EncodedTable(HNode node, BitSet bitset, Dictionary <byte, BitSet> table)
        {
            if (node.IsLeaf)
            {
                table.Add(node.Data, bitset);
                return;
            }


            EncodedTable(node.Left, new BitSet(bitset) + 0, table);
            EncodedTable(node.Right, new BitSet(bitset) + 1, table);
        }
Пример #2
0
        internal void Pass(HNode node, StringBuilder builder)
        {
            if (node == null)
            {
                return;
            }

            builder.Append("(");
            Pass(node.Left, builder);
            builder.Append(node);
            Pass(node.Right, builder);
            builder.Append(")");
        }
Пример #3
0
        private void Merge(HNode one, HNode other)
        {
            var node = new HNode(byte.MinValue, one.Count + other.Count);

            one.Parent = node;

            other.Parent = node;

            node.Left = one;

            node.Right = other;
            _nodeList.Add(node);
        }
Пример #4
0
        private void CreateTree()
        {
            while (true)
            {
                var hasntParentList = _nodeList.Where(node => !node.HasParent).OrderBy(node => node.Count).ToList();
                if (hasntParentList.Count <= 1)
                {
                    Root = hasntParentList[0];
                    break;
                }

                Merge(hasntParentList[0], hasntParentList[1]);
            }
        }