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 ++++++----------- src/lzss/lzssencoder.nim | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'src/lzss') 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) diff --git a/src/lzss/lzssencoder.nim b/src/lzss/lzssencoder.nim index 8b750fb..82fbe7b 100644 --- a/src/lzss/lzssencoder.nim +++ b/src/lzss/lzssencoder.nim @@ -17,7 +17,7 @@ import lists import listpolyfill, matchtable, lzssnode, lzsschain -const matchGroupLength = 3 +const matchGroupLength* = 3 const maxRefByteLength = high(uint8).int + matchGroupLength let emptySinglyLinkedList = initSinglyLinkedList[int]() -- cgit v1.2.3