def reserve_room_at

bend-collections@1.0.0.0 · src/containers/dynamic_array.bend:402

import bend-collections@1.0.0.0/src/containers/dynamic_array.bend as DynamicArray
import Base
import bend-collections@1.0.0.0/src/containers/types/dynamic_array.bend as E

402# The feasibility test (n <= 2^limit) is only reached when the cached capacity
403# does not already suffice: computing 2^limit is O(limit) and reserve is
404# otherwise O(1).
405def reserve_room_at(~T: Data, +limit: Nat, +depth: Nat, +cap: Nat, len: Nat, arr: Array<Maybe<&2, T>>, +n: Nat, feasible: Bool) -> DynArray<&2, T> & Result<&2, &2, E.Error, Unit>:
406  match feasible:
407    case True{}:
408      (grow_until_at(~T, Nat.sub(limit, depth), n, DA{limit, depth, cap, len, arr}), Done{Unit{}})
409    case False{}:
410      (DA{limit, depth, cap, len, arr}, Fail{E.CapacityExceeded{}})

Uses (12)

Used by (1)