def fit
import gralha-byte-words@0.1.0.0/words.bend as Wordsimport Base
20# the smallest depth d with 2^d >= need
21def fit(n: Nat, +d: U32, +need: U32, ok: Bool) -> U32:
22 match n, ok:
23 case k, True{}:
24 d
25 case 0n, False{}:
26 d
27 case 1n+p, False{}:
28 fit(p, (d + 1 : U32), need, U32.is_ge(U32.shln(1, U32.to_nat((d + 1 : U32))), need))