import math class Holder: pass def count(k, m, h=32): # log(2**m, base=k) = m * log(2, base=k) depth = m * math.log(2, k) # base=k if int(depth) != depth: # ceiling depth = float(int(depth)+1) readcap = Holder() readcap.small_hashes = k*4*m readcap.pubkey_hashes = k readcap.pubkey_hash_size = 2*m*h readcap.node_hash_size = k*h signature = Holder() signature.small_hashes = depth*k*4*m signature.large_hashes = depth signature.large_hash_size = k*h signature.publish_size = depth*(3*m+(k-1))*h return (readcap, signature) def abbreviate(s, bsuffix=""): U = 1000.0 def r(count, suffix): return "%.2f%s%s" % (count, suffix, bsuffix) if s < 1024: # 1000-1023 get emitted as bytes, even in SI mode return "%d" % s if s < U*U: return r(s/U, "k") if s < U*U*U: return r(s/(U*U), "M") if s < U*U*U*U: return r(s/(U*U*U), "G") if s < U*U*U*U*U: return r(s/(U*U*U*U), "T") return r(s/(U*U*U*U*U), "P") print "k=branch readcap | signature" print " factor small pubkey | small large large publish" print " hashes hashes | hashes hashes hashsize size" print "======== ====== ====== ======== ====== ======== =======" for k in [2**i for i in range(1,20)]: readcap, sig = count(k, 256) print ("%8d %9s %8s "+"%11s %6d %10d %10s") % \ (k, abbreviate(readcap.small_hashes), abbreviate(readcap.pubkey_hashes), abbreviate(sig.small_hashes), sig.large_hashes, sig.large_hash_size, abbreviate(sig.publish_size, "B"), )