MCPcopy Create free account
hub / github.com/ActiveState/code / decode

Function decode

recipes/Python/306626_arithmetic_coder/recipe-306626.py:76–95  ·  view source on GitHub ↗

decode the number to a string using the given statistics

(longval, nbits, probs)

Source from the content-addressed store, hash-verified

74
75
76def decode(longval, nbits, probs):
77 """decode the number to a string using the given statistics"""
78 val = R(longval, 1L<<nbits)
79 letters = []
80 probs_items = [(c, minval, maxval) for (c, (minval, maxval))
81 in probs.items()]
82
83 while 1:
84 for (c, minval, maxval) in probs_items:
85 if minval <= val < maxval:
86 break
87 else:
88 raise AssertionError("not found")
89
90 if c == "\x00":
91 break
92 letters.append(c)
93 delta = maxval - minval
94 val = (val - minval)/delta
95 return "".join(letters)
96
97if __name__ == "__main__":
98 # getopt? optparse? What are they?

Callers 1

recipe-306626.pyFile · 0.70

Calls 3

itemsMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected