diff options
Diffstat (limited to 'src/lzsschain.nim')
-rw-r--r-- | src/lzsschain.nim | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/src/lzsschain.nim b/src/lzsschain.nim deleted file mode 100644 index 44200f2..0000000 --- a/src/lzsschain.nim +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | # gzip-like LZSS compressor | ||
2 | # Copyright (C) 2018 Pacien TRAN-GIRARD | ||
3 | # | ||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU Affero General Public License as | ||
6 | # published by the Free Software Foundation, either version 3 of the | ||
7 | # License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU Affero General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU Affero General Public License | ||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | |||
17 | import lists, tables, sugar | ||
18 | import polyfill, integers, lzssnode, huffman/huffmantree | ||
19 | |||
20 | const maxChainByteLength = 32_000 * wordBitLength | ||
21 | |||
22 | type LzssChain* = | ||
23 | SinglyLinkedList[LzssNode] | ||
24 | |||
25 | proc lzssChain*(): LzssChain = | ||
26 | initSinglyLinkedList[LzssNode]() | ||
27 | |||
28 | proc decode*(lzssChain: LzssChain): seq[uint8] = | ||
29 | result = newSeqOfCap[uint8](maxChainByteLength) | ||
30 | for node in lzssChain.items: | ||
31 | case node.kind: | ||
32 | of character: | ||
33 | result.add(node.character) | ||
34 | of reference: | ||
35 | let absolutePos = result.len - node.relativePos | ||
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) | ||