diff --git a/src/zippy/compress.nim b/src/zippy/compress.nim index 32dfe83..57b5870 100644 --- a/src/zippy/compress.nim +++ b/src/zippy/compress.nim @@ -164,7 +164,7 @@ func huffmanCodeLengths( func findCodeIndex(a: openarray[uint16], value: uint16): uint16 = for i in 1 .. a.high: - if value < a[i]: + if value <= a[i]: return i.uint16 - 1 func lz77Encode(src: seq[uint8]): (seq[uint16], seq[uint64]) = @@ -370,7 +370,6 @@ func compress*(src: seq[uint8]): seq[uint8] = var i: int while i < encoded.len: let symbol = encoded[i] - # debugEcho "c: ", symbol, " ", llCodes[symbol], " ", if symbol <= 255: symbol.char else: 0.char b.addBits(llCodes[symbol], llLengths[symbol].int) inc i if symbol > 256: @@ -386,7 +385,6 @@ func compress*(src: seq[uint8]): seq[uint8] = b.addBits(lengthExtra, lengthExtraBits) b.addBits(distCodes[distIndex], distLengths[distIndex].int) b.addBits(distExtra, distExtraBits) - # debugEcho "cd: ", distIndex, " ", distCodes[distIndex] if llLengths[256] == 0: failCompress() diff --git a/src/zippy/uncompress.nim b/src/zippy/uncompress.nim index 70090e3..02c23ae 100644 --- a/src/zippy/uncompress.nim +++ b/src/zippy/uncompress.nim @@ -137,7 +137,6 @@ func inflateBlock(b: var BitStream, dst: var seq[uint8], fixedCodes: bool) = var pos = dst.len while true: let symbol = decodeSymbol(b, literalHuffman) - # debugEcho "u: ", symbol, " ", if symbol <= 255: symbol.char else: 0.char if symbol <= 255: if pos >= dst.len: dst.setLen((pos + 1) * 2) diff --git a/tests/lz77.nim b/tests/lz77.nim index 38ffaf4..2c3f13b 100644 --- a/tests/lz77.nim +++ b/tests/lz77.nim @@ -120,7 +120,7 @@ timeIt "lz77": for i in 0 ..< 1: for file in files: let - original = cast[seq[uint8]](readFile(&"data/{file}")) + original = cast[seq[uint8]](readFile(&"tests/data/{file}")) encoded = lz77Encode(original) decoded = lz77Decode(encoded) echo &"{file} original: {original.len} encoded: {encoded.len}"