def reserve_room

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

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

164# The feasibility test (n <= 2^limit) is only reached when the cached capacity
165# does not already suffice: computing 2^limit is O(limit) and reserve is
166# otherwise O(1).
167def reserve_room(-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>:
168  match feasible:
169    case True{}:
170      (grow_until(T, Nat.sub(limit, depth), n, DA{limit, depth, cap, len, arr}), Done{Unit{}})
171    case False{}:
172      (DA{limit, depth, cap, len, arr}, Fail{E.CapacityExceeded{}})

Uses (12)

Used by (1)