diff options
Diffstat (limited to 'src/lzss/lzsschain.nim')
-rw-r--r-- | src/lzss/lzsschain.nim | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/lzss/lzsschain.nim b/src/lzss/lzsschain.nim index 8b49914..8ebcb1a 100644 --- a/src/lzss/lzsschain.nim +++ b/src/lzss/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 ../bitio/integers, ../huffman/huffmantree | 18 | import ../bitio/integers |
19 | import listpolyfill, lzssnode | 19 | import listpolyfill, lzssnode |
20 | 20 | ||
21 | const maxChainByteLength = 32_000 * wordBitLength | 21 | const maxChainByteLength = 32_000 * wordBitLength |
@@ -26,6 +26,11 @@ type LzssChain* = | |||
26 | proc lzssChain*(): LzssChain = | 26 | proc lzssChain*(): LzssChain = |
27 | initSinglyLinkedList[LzssNode]() | 27 | initSinglyLinkedList[LzssNode]() |
28 | 28 | ||
29 | proc lzssChain*(chainArray: openArray[LzssNode]): LzssChain = | ||
30 | var chain = lzssChain() | ||
31 | for node in chainArray: chain.append(node) | ||
32 | chain | ||
33 | |||
29 | proc decode*(lzssChain: LzssChain): seq[uint8] = | 34 | proc decode*(lzssChain: LzssChain): seq[uint8] = |
30 | result = newSeqOfCap[uint8](maxChainByteLength) | 35 | result = newSeqOfCap[uint8](maxChainByteLength) |
31 | for node in lzssChain.items: | 36 | for node in lzssChain.items: |
@@ -35,13 +40,3 @@ proc decode*(lzssChain: LzssChain): seq[uint8] = | |||
35 | of reference: | 40 | of reference: |
36 | let absolutePos = result.len - node.relativePos | 41 | let absolutePos = result.len - node.relativePos |
37 | result.add(result.toOpenArray(absolutePos, absolutePos + node.length - 1)) | 42 | result.add(result.toOpenArray(absolutePos, absolutePos + node.length - 1)) |
38 | |||
39 | proc stats*(lzssChain: LzssChain): tuple[characters: CountTableRef[uint8], lengths, positions: CountTableRef[int]] = | ||
40 | result = (newCountTable[uint8](), newCountTable[int](), newCountTable[int]()) | ||
41 | for node in lzssChain.items: | ||
42 | case node.kind: | ||
43 | of character: | ||
44 | result.characters.inc(node.character) | ||
45 | of reference: | ||
46 | result.lengths.inc(node.length) | ||
47 | result.positions.inc(node.relativePos) | ||