aboutsummaryrefslogtreecommitdiff
path: root/src/lzsshuffman
diff options
context:
space:
mode:
Diffstat (limited to 'src/lzsshuffman')
-rw-r--r--src/lzsshuffman/lzsshuffmandecoder.nim7
-rw-r--r--src/lzsshuffman/lzsshuffmanencoder.nim5
-rw-r--r--src/lzsshuffman/lzsshuffmanstats.nim2
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
17import lists
18import ../bitio/bitreader 17import ../bitio/bitreader
19import ../lzss/listpolyfill, ../lzss/lzssnode, ../lzss/lzsschain 18import ../lzss/lzssnode, ../lzss/lzsschain
20import ../huffman/huffmantree, ../huffman/huffmandecoder 19import ../huffman/huffmantree, ../huffman/huffmandecoder
21import lzsshuffmansymbol 20import 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
17import lists
18import ../bitio/bitwriter 17import ../bitio/bitwriter
19import ../lzss/listpolyfill, ../lzss/lzssnode, ../lzss/lzsschain, ../lzss/lzssencoder 18import ../lzss/lzssnode, ../lzss/lzsschain, ../lzss/lzssencoder
20import ../huffman/huffmantree, ../huffman/huffmantreebuilder, ../huffman/huffmanencoder 19import ../huffman/huffmantree, ../huffman/huffmantreebuilder, ../huffman/huffmanencoder
21import lzsshuffmansymbol 20import 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
26proc writeChain*(lzssChain: LzssChain, symbolEncoder, positionEncoder: HuffmanEncoder[uint16, uint16], bitWriter: BitWriter) = 25proc 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
21proc aggregateStats*(chain: LzssChain): tuple[symbolTable, positionTable: CountTableRef[uint16]] = 21proc 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)