import math
word_size = 8
word_buckets_limit = 256
double_buckets_limit = 512
exp_fractions = 4
min_chunk_size = word_size * 3
word_bins_count = (word_buckets_limit - min_chunk_size) // word_size
print("word bins count:", word_bins_count)
for i, sb in enumerate(range(min_chunk_size, word_buckets_limit, word_size)):
print("{1:>3}: {0:>8} {0:>20b} | ".format(sb, i), end='\n')
double_bins_count = (double_buckets_limit - word_buckets_limit) // (2*word_size)
print("double bins count:", double_bins_count)
for i, bsb in enumerate(range(word_buckets_limit, double_buckets_limit, 2*word_size)):
print("{1:>3}: {0:>8} {0:>20b} | ".format(bsb, i), end='\n')
print("pseudo log-spaced bins")
b_ofst = int(math.log2(double_buckets_limit)) b_p2dv = int(math.log2(exp_fractions))
for b in range(0, (word_size * 8 * 2) - word_bins_count - double_bins_count):
size = ((1 << b_p2dv) + (b & ((1<<b_p2dv)-1))) << ((b >> b_p2dv) + (b_ofst-b_p2dv))
size_log2 = math.floor(math.log2(size))
b_calc = ((size >> size_log2 - b_p2dv) ^ (1<<b_p2dv)) + ((size_log2-b_ofst) << b_p2dv)
assert b == b_calc
print("{1:>3}: {0:>8} {0:>20b} | ".format(size, b + word_bins_count + double_bins_count), end='\n')