From 5cc4256a931b98ea167291397421d0db60c5d40c Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 2 Dec 2018 00:22:56 +0100 Subject: implement lzss block --- src/lzss/lzsschain.nim | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/lzss/lzsschain.nim') 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 @@ # along with this program. If not, see . import lists, tables, sugar -import ../bitio/integers, ../huffman/huffmantree +import ../bitio/integers import listpolyfill, lzssnode const maxChainByteLength = 32_000 * wordBitLength @@ -26,6 +26,11 @@ type LzssChain* = proc lzssChain*(): LzssChain = initSinglyLinkedList[LzssNode]() +proc lzssChain*(chainArray: openArray[LzssNode]): LzssChain = + var chain = lzssChain() + for node in chainArray: chain.append(node) + chain + proc decode*(lzssChain: LzssChain): seq[uint8] = result = newSeqOfCap[uint8](maxChainByteLength) for node in lzssChain.items: @@ -35,13 +40,3 @@ proc decode*(lzssChain: LzssChain): seq[uint8] = of reference: let absolutePos = result.len - node.relativePos result.add(result.toOpenArray(absolutePos, absolutePos + node.length - 1)) - -proc stats*(lzssChain: LzssChain): tuple[characters: CountTableRef[uint8], lengths, positions: CountTableRef[int]] = - result = (newCountTable[uint8](), newCountTable[int](), newCountTable[int]()) - for node in lzssChain.items: - case node.kind: - of character: - result.characters.inc(node.character) - of reference: - result.lengths.inc(node.length) - result.positions.inc(node.relativePos) -- cgit v1.2.3