in multiset_codec/msbst.py [0:0]
def forward_lookup(multiset, x):
'''
Looks up the cumulative (start) and frequency (freq) counts of symbol x.
'''
if not multiset:
raise ValueError("The symbol {} could not be found.".format(x))
size, y, left, right = multiset
if x > y:
start_right, freq = forward_lookup(right, x)
start = size - right[0] + start_right
elif x < y:
start, freq = forward_lookup(left, x)
else:
start = left[0] if left else 0
freq = size - start - (right[0] if right else 0)
return start, freq