Blake3.tree: def of bend-collections-laws-crypto@1.0.0.0 Import: import bend-collections-laws-crypto@1.0.0.0/spec/crypto/blake/blake3.bend as Blake3 Lines 244-257 of bend-collections-laws-crypto@1.0.0.0/spec/crypto/blake/blake3.bend: https://jend.leeeet.dev/read.txt?path=bend-collections-laws-crypto@1.0.0.0/spec/crypto/blake/blake3.bend&start_line=244&end_line=257 import Base import bend-collections-laws-crypto@1.0.0.0/src/crypto/blake/blake3/types.bend as T import bend-collections-laws-crypto@1.0.0.0/spec/lib/common.bend as SC # The tree over the chunk outputs xs, 1 <= |xs| <= 2^h. The chunks are its # leaves in order; a left subtree is always complete with a power of two of # chunks, the largest one that leaves at least one chunk to its right: with # h = g+1 and |xs| > 2^g the left subtree takes the first 2^g chunks and the # right one the rest, while |xs| <= 2^g (nothing left for the right) means the # tree already fits in height g. def tree(+h: Nat, +xs: List<&2,T.Out>) -> T.Out: match h xs: case 0n Nil{}: first(Nil{}) case 0n Con{+x,+r}: first(Con{x,r}) case 1n+g Nil{}: first(Nil{}) case 1n+g Con{+x,+r}: +k = SC.pow2(g) join(tree(g,SC.take(T.Out,Con{x,r},k)),tree(g,SC.drop(T.Out,Con{x,r},k)),is_nil(SC.drop(T.Out,Con{x,r},k))) Uses (9): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=bend-collections-laws-crypto@1.0.0.0/spec/crypto/blake/blake3.bend&name=first https://jend.leeeet.dev/definition.txt?path=bend-collections-laws-crypto@1.0.0.0/spec/crypto/blake/blake3.bend&name=is_nil https://jend.leeeet.dev/definition.txt?path=bend-collections-laws-crypto@1.0.0.0/spec/crypto/blake/blake3.bend&name=join https://jend.leeeet.dev/definition.txt?path=bend-collections-laws-crypto@1.0.0.0/spec/lib/common.bend&name=drop https://jend.leeeet.dev/definition.txt?path=bend-collections-laws-crypto@1.0.0.0/spec/lib/common.bend&name=pow2 https://jend.leeeet.dev/definition.txt?path=bend-collections-laws-crypto@1.0.0.0/spec/lib/common.bend&name=take https://jend.leeeet.dev/definition.txt?path=bend-collections-laws-crypto@1.0.0.0/src/crypto/blake/blake3/types.bend&name=Out