diff options
author | pacien | 2018-12-02 00:22:56 +0100 |
---|---|---|
committer | pacien | 2018-12-02 00:22:56 +0100 |
commit | 5cc4256a931b98ea167291397421d0db60c5d40c (patch) | |
tree | 54c7ba39e69fb31322db431a82dbf31aedbb53b9 /src/huffman | |
parent | 1850acb5b77aabbf4e9ba24ae6d5314c3d4d896a (diff) | |
download | gziplike-5cc4256a931b98ea167291397421d0db60c5d40c.tar.gz |
implement lzss block
Diffstat (limited to 'src/huffman')
-rw-r--r-- | src/huffman/huffmantree.nim | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/huffman/huffmantree.nim b/src/huffman/huffmantree.nim index 58a840e..f3fce1b 100644 --- a/src/huffman/huffmantree.nim +++ b/src/huffman/huffmantree.nim | |||
@@ -31,6 +31,11 @@ type HuffmanTreeNode*[T: SomeUnsignedInt] = ref object | |||
31 | of leaf: | 31 | of leaf: |
32 | value*: T | 32 | value*: T |
33 | 33 | ||
34 | proc maxValue*[T](node: HuffmanTreeNode[T]): T = | ||
35 | case node.kind: | ||
36 | of branch: node.maxChildValue | ||
37 | of leaf: node.value | ||
38 | |||
34 | proc huffmanBranch*[T](left, right: HuffmanTreeNode[T]): HuffmanTreeNode[T] = | 39 | proc huffmanBranch*[T](left, right: HuffmanTreeNode[T]): HuffmanTreeNode[T] = |
35 | HuffmanTreeNode[T]( | 40 | HuffmanTreeNode[T]( |
36 | kind: branch, left: left, right: right, | 41 | kind: branch, left: left, right: right, |
@@ -45,11 +50,6 @@ proc `==`*[T](a, b: HuffmanTreeNode[T]): bool = | |||
45 | of branch: a.left == b.left and a.right == b.right | 50 | of branch: a.left == b.left and a.right == b.right |
46 | of leaf: a.value == b.value | 51 | of leaf: a.value == b.value |
47 | 52 | ||
48 | proc maxValue*[T](node: HuffmanTreeNode[T]): T = | ||
49 | case node.kind: | ||
50 | of branch: node.maxChildValue | ||
51 | of leaf: node.value | ||
52 | |||
53 | proc deserialise*[T](bitReader: BitReader, valueType: typedesc[T]): HuffmanTreeNode[T] = | 53 | proc deserialise*[T](bitReader: BitReader, valueType: typedesc[T]): HuffmanTreeNode[T] = |
54 | let valueBitLength = bitReader.readBits(valueLengthFieldBitLength, uint8).int | 54 | let valueBitLength = bitReader.readBits(valueLengthFieldBitLength, uint8).int |
55 | proc readNode(): HuffmanTreeNode[T] = | 55 | proc readNode(): HuffmanTreeNode[T] = |