Fix bug where huffman codec died if given empty freqs dict.

This commit is contained in:
Matthew Honnibal 2016-10-23 16:28:05 +02:00
parent 99ff8b902f
commit 49c117960c
1 changed files with 7 additions and 5 deletions

View File

@ -46,9 +46,11 @@ cdef class HuffmanCodec:
item.first = item1.first + item2.first
item.second = self.nodes.size()-1
queue.push(item)
# Careful of empty freqs dicts
cdef Code path
if queue.size() >= 1:
item = queue.top()
self.root = self.nodes[item.second]
cdef Code path
path.bits = 0
path.length = 0
assign_codes(self.nodes, self.codes, item.second, path)