aboutsummaryrefslogtreecommitdiff
path: root/src/lzss
diff options
context:
space:
mode:
Diffstat (limited to 'src/lzss')
-rw-r--r--src/lzss/lzsschain.nim17
-rw-r--r--src/lzss/lzssencoder.nim2
2 files changed, 7 insertions, 12 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
17import lists, tables, sugar 17import lists, tables, sugar
18import ../bitio/integers, ../huffman/huffmantree 18import ../bitio/integers
19import listpolyfill, lzssnode 19import listpolyfill, lzssnode
20 20
21const maxChainByteLength = 32_000 * wordBitLength 21const maxChainByteLength = 32_000 * wordBitLength
@@ -26,6 +26,11 @@ type LzssChain* =
26proc lzssChain*(): LzssChain = 26proc lzssChain*(): LzssChain =
27 initSinglyLinkedList[LzssNode]() 27 initSinglyLinkedList[LzssNode]()
28 28
29proc lzssChain*(chainArray: openArray[LzssNode]): LzssChain =
30 var chain = lzssChain()
31 for node in chainArray: chain.append(node)
32 chain
33
29proc decode*(lzssChain: LzssChain): seq[uint8] = 34proc 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
39proc 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)
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 @@
17import lists 17import lists
18import listpolyfill, matchtable, lzssnode, lzsschain 18import listpolyfill, matchtable, lzssnode, lzsschain
19 19
20const matchGroupLength = 3 20const matchGroupLength* = 3
21const maxRefByteLength = high(uint8).int + matchGroupLength 21const maxRefByteLength = high(uint8).int + matchGroupLength
22let emptySinglyLinkedList = initSinglyLinkedList[int]() 22let emptySinglyLinkedList = initSinglyLinkedList[int]()
23 23