Make HuffmanLength Comparable and use this in their sorting in HuffmanTree

This commit is contained in:
Timofey Solomko
2017-09-03 20:04:44 +03:00
parent f96f446827
commit cebf0555e5
3 changed files with 18 additions and 14 deletions
+1 -7
View File
@@ -16,13 +16,7 @@ class EncodingHuffmanTree {
self.bitWriter = bitWriter
// Sort `lengths` array to calculate canonical Huffman code.
let sortedLengths = lengths.sorted { (left: HuffmanLength, right: HuffmanLength) -> Bool in
if left.codeLength == right.codeLength {
return left.symbol < right.symbol
} else {
return left.codeLength < right.codeLength
}
}
let sortedLengths = lengths.sorted()
func reverse(bits: Int, in symbol: Int) -> Int {
// Auxiliarly function, which generates reversed order of bits in a number.