public HuffmanTreeNode(byte b, int freq, HuffmanTreeNode left, HuffmanTreeNode right) { bytev = b; this.freq = freq; this.left = left; this.right = right; }
void swap(ref HuffmanTreeNode a, ref HuffmanTreeNode b) { var c = a; a = b; b = c; }
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); } }
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); }
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); } }
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)); } } }
public HuffmanTreeNode(byte b) { bytev = b; freq = 0; left = right = null; }
void printHtinFile(FileStream fs) { HuffmanTreeNode.PrintInFile(fs, head); }
public HuffmanTree(HuffmanTreeNode hd) { head = hd; }
public HuffmanTree(byte v) { head = new HuffmanTreeNode(v); }
public HuffmanTree() { head = null; }
public static bool isLeaf(HuffmanTreeNode n) => n.left == null && n.right == null;
public HuffmanTreeNode(byte b, int freq) { bytev = b; this.freq = freq; left = right = null; }