mirror of
https://github.com/explosion/spaCy.git
synced 2025-03-03 10:55:52 +03:00
Fix bug where huffman codec died if given empty freqs dict.
This commit is contained in:
parent
99ff8b902f
commit
49c117960c
|
@ -46,12 +46,14 @@ cdef class HuffmanCodec:
|
||||||
item.first = item1.first + item2.first
|
item.first = item1.first + item2.first
|
||||||
item.second = self.nodes.size()-1
|
item.second = self.nodes.size()-1
|
||||||
queue.push(item)
|
queue.push(item)
|
||||||
item = queue.top()
|
# Careful of empty freqs dicts
|
||||||
self.root = self.nodes[item.second]
|
|
||||||
cdef Code path
|
cdef Code path
|
||||||
path.bits = 0
|
if queue.size() >= 1:
|
||||||
path.length = 0
|
item = queue.top()
|
||||||
assign_codes(self.nodes, self.codes, item.second, path)
|
self.root = self.nodes[item.second]
|
||||||
|
path.bits = 0
|
||||||
|
path.length = 0
|
||||||
|
assign_codes(self.nodes, self.codes, item.second, path)
|
||||||
|
|
||||||
def encode(self, msg, BitArray bits=None):
|
def encode(self, msg, BitArray bits=None):
|
||||||
if bits is None:
|
if bits is None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user