def swap_go
bendtorch-core@0.1.0.0 · src/storage/refinement.bend:159
import bendtorch-core@0.1.0.0/src/storage/refinement.bend as Refinement
import Base
import bendtorch-core@0.1.0.0/src/storage/model.bend as Model
159def swap_go(-T: Data, d: Nat, array: Array<T>, +n: U32, +i: U32, new: T, z: Bool,
160 valid: Model.Balanced(T, d, array)) -> Swap<T, d, array, n, i, z, new>:
161 match d array z:
162 case 0n ALeaf{old} _:
163 Swap{ALeaf{new}, old, {==}, {==}, {==}, valid}
164 case 0n ANode{xs, ys} _:
165 match valid:
166 case 1n+p ALeaf{old} _:
167 match valid:
168 case 1n+p ANode{xs, ys} True{}:
169 (ex, ey) = valid
170 swap_low(T, p, xs, n, i, new, ys,
171 swap_go(T, p, xs, U32.shr(n), i, new,
172 U32.is_lt(i, U32.shr(U32.shr(n))), ex), ey)
173 case 1n+p ANode{xs, ys} False{}:
174 (ex, ey) = valid
175 +j = U32.sub(i, U32.shr(n))
176 swap_high(T, p, ys, n, i, new, xs,
177 swap_go(T, p, ys, U32.shr(n), j, new,
178 U32.is_lt(j, U32.shr(U32.shr(n))), ey), ex)