def Array.swap.go

Base · base.bend:2466

import Base
2466# the recursion descends into a subtree, and z says which: the caller
2467# computes it from the index and the subtree's half size
2468def Array.swap.go(-T: Type, a: Array<T>, n: U32, +i: U32, v: T, z: Bool) -> Array<T> & T:
2469  match a z:
2470    case ALeaf{x} _:
2471      (ALeaf{v}, x)
2472    case ANode{xs, ys} True{}:
2473      +h = U32.shr(n)
2474      Array.swap.lo(T, ys, Array.swap.go(T, xs, h, i, v, U32.is_lt(i, U32.shr(h))))
2475    case ANode{xs, ys} False{}:
2476      +h = U32.shr(n)
2477      +j = U32.sub(i, h)
2478      Array.swap.hi(T, xs, Array.swap.go(T, ys, h, j, v, U32.is_lt(j, U32.shr(h))))

Uses (10)

Used by (38)