Rewrite to_rugbits

This commit is contained in:
mmcwilliams 2024-06-28 12:42:29 -04:00
parent 5e9d84fa94
commit 95b769f165
1 changed files with 12 additions and 1 deletions

View File

@ -165,7 +165,7 @@ class WordHasher(object):
return N
def to_rugbits(self, integer):
def to_rugbits_old(self, integer):
"""Convert a 45bit `integer` to a list of 3rugbits
A rugbit is like a byte but with 15bits instead of eight.
@ -176,6 +176,17 @@ class WordHasher(object):
integer & fifteen_bits]
return rugbits
def to_rugbits(self, integer):
"""Convert a 45bit `integer` to a list of 3rugbits
A rugbit is like a byte but with 15bits instead of eight.
"""
fifteen_bits = 0b111111111111111
rugbits = [(integer >> 30) & fifteen_bits,
(integer >> 15) & fifteen_bits,
integer & fifteen_bits]
return rugbits
def rugbits_to_int(self, rugbits):
"""Convert a list of `rugbits` to an integer"""
assert len(rugbits) == 3