예제 #1
0
 public HuffmanTreeNode(byte b, int freq, HuffmanTreeNode left, HuffmanTreeNode right)
 {
     bytev      = b;
     this.freq  = freq;
     this.left  = left;
     this.right = right;
 }
예제 #2
0
        void swap(ref HuffmanTreeNode a, ref HuffmanTreeNode b)
        {
            var c = a;

            a = b;
            b = c;
        }
예제 #3
0
 public static void PrintInFile(FileStream fs, HuffmanTreeNode node)
 {
     if (node != null)
     {
         if (isLeaf(node) && (node.bytev == (byte)'*' || node.bytev == (byte)'\\'))
         {
             fs.WriteByte(node.bytev);
         }
         PrintInFile(fs, node.left);
         PrintInFile(fs, node.right);
     }
 }
예제 #4
0
        public HuffmanTree CreateHuffmanTree()
        {
            HuffmanTree huff;

            while (size > 1)
            {
                var a   = pop();
                var b   = pop();
                var tmp = new HuffmanTreeNode((byte)'*', a.freq + b.freq, a, b);
                Push(tmp);
            }
            huff = new HuffmanTree(pop());
            return(huff);
        }
예제 #5
0
        public void Push(HuffmanTreeNode node)
        {
            size++;
            heap[size] = node;
            int key    = size;
            int parent = getParent(key);

            while (parent >= 1 && ((heap[key]) <= heap[parent]))
            {
                swap(ref heap[key], ref heap[parent]);
                key    = parent;
                parent = getParent(parent);
            }
        }
예제 #6
0
 private void SetTree(HuffmanTreeNode ht, HashTable t, short height, short value)
 {
     if (ht != null)
     {
         if (HuffmanTreeNode.isLeaf(ht))
         {
             if (ht.bytev == '*' || ht.bytev == '\\')
             {
                 height--;
                 value = (short)(value >> 1);
             }
             t.put(ht.bytev, value, height);
             SetTree(ht.left, t, (short)(height + 1), (short)(value << 1));
             SetTree(ht.right, t, (short)(height + 1), (short)((value << 1) + 1));
         }
     }
 }
예제 #7
0
 public HuffmanTreeNode(byte b)
 {
     bytev = b;
     freq  = 0;
     left  = right = null;
 }
예제 #8
0
 void printHtinFile(FileStream fs)
 {
     HuffmanTreeNode.PrintInFile(fs, head);
 }
예제 #9
0
 public HuffmanTree(HuffmanTreeNode hd)
 {
     head = hd;
 }
예제 #10
0
 public HuffmanTree(byte v)
 {
     head = new HuffmanTreeNode(v);
 }
예제 #11
0
 public HuffmanTree()
 {
     head = null;
 }
예제 #12
0
 public static bool isLeaf(HuffmanTreeNode n) => n.left == null && n.right == null;
예제 #13
0
 public HuffmanTreeNode(byte b, int freq)
 {
     bytev     = b;
     this.freq = freq;
     left      = right = null;
 }