diff options
author | pacien | 2018-12-02 00:38:12 +0100 |
---|---|---|
committer | pacien | 2018-12-02 00:38:12 +0100 |
commit | 56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac (patch) | |
tree | d42919fdf57f7f014ca0c0db1a7a55e1465a0135 /src/lzsshuffman | |
parent | 5cc4256a931b98ea167291397421d0db60c5d40c (diff) | |
download | gziplike-56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac.tar.gz |
replace linkedlists by seqs
Diffstat (limited to 'src/lzsshuffman')
-rw-r--r-- | src/lzsshuffman/lzsshuffmandecoder.nim | 7 | ||||
-rw-r--r-- | src/lzsshuffman/lzsshuffmanencoder.nim | 5 | ||||
-rw-r--r-- | src/lzsshuffman/lzsshuffmanstats.nim | 2 |
3 files changed, 6 insertions, 8 deletions
diff --git a/src/lzsshuffman/lzsshuffmandecoder.nim b/src/lzsshuffman/lzsshuffmandecoder.nim index cd71914..a307774 100644 --- a/src/lzsshuffman/lzsshuffmandecoder.nim +++ b/src/lzsshuffman/lzsshuffmandecoder.nim | |||
@@ -14,9 +14,8 @@ | |||
14 | # You should have received a copy of the GNU Affero General Public License | 14 | # You should have received a copy of the GNU Affero General Public License |
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 | ||
18 | import ../bitio/bitreader | 17 | import ../bitio/bitreader |
19 | import ../lzss/listpolyfill, ../lzss/lzssnode, ../lzss/lzsschain | 18 | import ../lzss/lzssnode, ../lzss/lzsschain |
20 | import ../huffman/huffmantree, ../huffman/huffmandecoder | 19 | import ../huffman/huffmantree, ../huffman/huffmandecoder |
21 | import lzsshuffmansymbol | 20 | import lzsshuffmansymbol |
22 | 21 | ||
@@ -26,9 +25,9 @@ proc readChain*(bitReader: BitReader, symbolDecoder, positionDecoder: HuffmanDec | |||
26 | while not symbol.isEndMarker(): | 25 | while not symbol.isEndMarker(): |
27 | if byteCursor > maxDataByteLength: raise newException(IOError, "lzss block too long") | 26 | if byteCursor > maxDataByteLength: raise newException(IOError, "lzss block too long") |
28 | if symbol.isCharacter(): | 27 | if symbol.isCharacter(): |
29 | chain.append(lzssCharacter(symbol.uint8)) | 28 | chain.add(lzssCharacter(symbol.uint8)) |
30 | else: | 29 | else: |
31 | let position = positionDecoder.decode(bitReader) | 30 | let position = positionDecoder.decode(bitReader) |
32 | chain.append(unpackLzssReference(symbol, position)) | 31 | chain.add(unpackLzssReference(symbol, position)) |
33 | (symbol, byteCursor) = (symbolDecoder.decode(bitReader).Symbol, byteCursor + 1) | 32 | (symbol, byteCursor) = (symbolDecoder.decode(bitReader).Symbol, byteCursor + 1) |
34 | chain | 33 | chain |
diff --git a/src/lzsshuffman/lzsshuffmanencoder.nim b/src/lzsshuffman/lzsshuffmanencoder.nim index ea89f85..205f464 100644 --- a/src/lzsshuffman/lzsshuffmanencoder.nim +++ b/src/lzsshuffman/lzsshuffmanencoder.nim | |||
@@ -14,9 +14,8 @@ | |||
14 | # You should have received a copy of the GNU Affero General Public License | 14 | # You should have received a copy of the GNU Affero General Public License |
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 | ||
18 | import ../bitio/bitwriter | 17 | import ../bitio/bitwriter |
19 | import ../lzss/listpolyfill, ../lzss/lzssnode, ../lzss/lzsschain, ../lzss/lzssencoder | 18 | import ../lzss/lzssnode, ../lzss/lzsschain, ../lzss/lzssencoder |
20 | import ../huffman/huffmantree, ../huffman/huffmantreebuilder, ../huffman/huffmanencoder | 19 | import ../huffman/huffmantree, ../huffman/huffmantreebuilder, ../huffman/huffmanencoder |
21 | import lzsshuffmansymbol | 20 | import lzsshuffmansymbol |
22 | 21 | ||
@@ -24,7 +23,7 @@ proc writeSymbol(bitWriter: BitWriter, encodedSymbol: tuple[bitLength: int, valu | |||
24 | bitWriter.writeBits(encodedSymbol.bitLength, encodedSymbol.value) | 23 | bitWriter.writeBits(encodedSymbol.bitLength, encodedSymbol.value) |
25 | 24 | ||
26 | proc writeChain*(lzssChain: LzssChain, symbolEncoder, positionEncoder: HuffmanEncoder[uint16, uint16], bitWriter: BitWriter) = | 25 | proc writeChain*(lzssChain: LzssChain, symbolEncoder, positionEncoder: HuffmanEncoder[uint16, uint16], bitWriter: BitWriter) = |
27 | for node in lzssChain.items: | 26 | for node in lzssChain: |
28 | case node.kind: | 27 | case node.kind: |
29 | of character: | 28 | of character: |
30 | bitWriter.writeSymbol(symbolEncoder.encode(node.character)) | 29 | bitWriter.writeSymbol(symbolEncoder.encode(node.character)) |
diff --git a/src/lzsshuffman/lzsshuffmanstats.nim b/src/lzsshuffman/lzsshuffmanstats.nim index 037ce5f..d5c1f3e 100644 --- a/src/lzsshuffman/lzsshuffmanstats.nim +++ b/src/lzsshuffman/lzsshuffmanstats.nim | |||
@@ -20,7 +20,7 @@ import lzsshuffmansymbol | |||
20 | 20 | ||
21 | proc aggregateStats*(chain: LzssChain): tuple[symbolTable, positionTable: CountTableRef[uint16]] = | 21 | proc aggregateStats*(chain: LzssChain): tuple[symbolTable, positionTable: CountTableRef[uint16]] = |
22 | var (symbolTable, positionTable) = (newCountTable[uint16](), newCountTable[uint16]()) | 22 | var (symbolTable, positionTable) = (newCountTable[uint16](), newCountTable[uint16]()) |
23 | for node in chain.items: | 23 | for node in chain: |
24 | case node.kind: | 24 | case node.kind: |
25 | of character: | 25 | of character: |
26 | symbolTable.inc(node.character) | 26 | symbolTable.inc(node.character) |