diff options
Diffstat (limited to 'src/lzsschain.nim')
-rw-r--r-- | src/lzsschain.nim | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lzsschain.nim b/src/lzsschain.nim index 8203cb8..073aa5e 100644 --- a/src/lzsschain.nim +++ b/src/lzsschain.nim | |||
@@ -15,7 +15,7 @@ | |||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | import lists, tables, sugar | 17 | import lists, tables, sugar |
18 | import polyfill, integers, lzssnode | 18 | import polyfill, integers, lzssnode, huffmantree |
19 | 19 | ||
20 | const maxChainByteLength = 32_000 * wordBitLength | 20 | const maxChainByteLength = 32_000 * wordBitLength |
21 | 21 | ||
@@ -34,3 +34,13 @@ proc decode*(lzssChain: LzssChain): seq[uint8] = | |||
34 | of reference: | 34 | of reference: |
35 | let absolutePos = result.len - node.relativePos | 35 | let absolutePos = result.len - node.relativePos |
36 | result.add(result.toOpenArray(absolutePos, absolutePos + node.length - 1)) | 36 | result.add(result.toOpenArray(absolutePos, absolutePos + node.length - 1)) |
37 | |||
38 | proc stats*(lzssChain: LzssChain): tuple[characters: CountTableRef[uint8], lengths, positions: CountTableRef[int]] = | ||
39 | result = (newCountTable[uint8](), newCountTable[int](), newCountTable[int]()) | ||
40 | for node in lzssChain.items: | ||
41 | case node.kind: | ||
42 | of character: | ||
43 | result.characters.inc(node.character) | ||
44 | of reference: | ||
45 | result.lengths.inc(node.length) | ||
46 | result.positions.inc(node.relativePos) | ||