This commit is contained in:
Connor 2018-09-11 14:03:16 -07:00 committed by GitHub
parent 248a9c0305
commit dfe69c396f

View file

@ -27,8 +27,6 @@ def encode(string, c0=BETA0, c1=BETA1, adaptive=True):
b = ONE
a = 0
tot0 = 0
tot1 = 0
if not adaptive:
p0 = c0 / (c0 + c1)
ans = ""
@ -54,15 +52,13 @@ def encode(string, c0=BETA0, c1=BETA1, adaptive=True):
if c == '1':
a = boundary
tot1 += 1
if adaptive:
c1 += 1
elif c == '0':
b = boundary
tot0 += 1
if adaptive:
c0 += 1
# ignore other characters
# ignore other characters
while a >= HALF or b <= HALF: # output bits
if a >= HALF:
@ -116,8 +112,6 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
b = ONE
a = 0
tot0 = 0
tot1 = 0
model_needs_updating = True
if not adaptive:
p0 = c0 / (c0 + c1)
@ -129,6 +123,7 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
if N <= 0:
break # out of the string-reading loop
assert N > 0
# (u,v) is the current "encoded alphabet" binary interval,
# and halfway is its midpoint.
# (a,b) is the current "source alphabet" interval,
@ -161,7 +156,6 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
if boundary <= u:
ans += "1"
tot1 += 1
if adaptive:
c1 += 1
a = boundary
@ -169,7 +163,6 @@ def decode(string, N, c0=BETA0, c1=BETA1, adaptive=True):
N -= 1
elif boundary >= v:
ans += "0"
tot0 += 1
if adaptive:
c0 += 1
b = boundary