diff options
author | pacien | 2018-12-02 00:22:56 +0100 |
---|---|---|
committer | pacien | 2018-12-02 00:22:56 +0100 |
commit | 5cc4256a931b98ea167291397421d0db60c5d40c (patch) | |
tree | 54c7ba39e69fb31322db431a82dbf31aedbb53b9 /src/lzss | |
parent | 1850acb5b77aabbf4e9ba24ae6d5314c3d4d896a (diff) | |
download | gziplike-5cc4256a931b98ea167291397421d0db60c5d40c.tar.gz |
implement lzss block
Diffstat (limited to 'src/lzss')
-rw-r--r-- | src/lzss/lzsschain.nim | 17 | ||||
-rw-r--r-- | src/lzss/lzssencoder.nim | 2 |
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 | ||
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) | ||
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 @@ | |||
17 | import lists | 17 | import lists |
18 | import listpolyfill, matchtable, lzssnode, lzsschain | 18 | import listpolyfill, matchtable, lzssnode, lzsschain |
19 | 19 | ||
20 | const matchGroupLength = 3 | 20 | const matchGroupLength* = 3 |
21 | const maxRefByteLength = high(uint8).int + matchGroupLength | 21 | const maxRefByteLength = high(uint8).int + matchGroupLength |
22 | let emptySinglyLinkedList = initSinglyLinkedList[int]() | 22 | let emptySinglyLinkedList = initSinglyLinkedList[int]() |
23 | 23 | ||