Update huffman codes

This commit is contained in:
Tatsuhiro Tsujikawa 2014-04-02 01:44:39 +09:00
parent b1722cbe28
commit e5b0303481
2 changed files with 5092 additions and 5092 deletions

File diff suppressed because it is too large Load Diff

View File

@ -120,18 +120,18 @@ tables = {}
root = Node() root = Node()
for line in sys.stdin: for line in sys.stdin:
m = re.match(r'.*\(\s*(\d+)\) ([|01]+) \[(\d+)\]\s+(\S+).*', line) m = re.match(r'.*\(\s*(\d+)\)\s+([|01]+)\s+(\S+)\s+\[\s*(\d+)\].*', line)
if m: if m:
#print m.group(1), m.group(2), m.group(3) #print m.group(1), m.group(2), m.group(4)
if len(m.group(4)) > 8: if len(m.group(3)) > 8:
raise Error('Code is more than 4 bytes long') raise Error('Code is more than 4 bytes long')
sym = int(m.group(1)) sym = int(m.group(1))
bits = re.sub(r'\|', '', m.group(2)) bits = re.sub(r'\|', '', m.group(2))
nbits = int(m.group(3)) nbits = int(m.group(4))
assert(len(bits) == nbits) assert(len(bits) == nbits)
binpat = to_bin(bits) binpat = to_bin(bits)
assert(len(binpat) == (nbits+7)/8) assert(len(binpat) == (nbits+7)/8)
symbol_tbl[sym] = (binpat, nbits, m.group(4)) symbol_tbl[sym] = (binpat, nbits, m.group(3))
#print "Inserting", sym #print "Inserting", sym
insert(root, sym, bits) insert(root, sym, bits)