Arrays of UInt16: basics #
The type, its model, and the operations compiled to the runtime: reads, writes,
push, capacity, append and copySlice.
Arrays of UInt16 values, stored unboxed in a scalar array, 2 bytes per element.
The logical model is an Array UInt16: UInt16Array.mk and UInt16Array.toArray convert between
the two. cases and induction split a UInt16Array as mk a.
Instances For
The UInt16Array whose elements are a.
Instances For
The number of elements of a.
Instances For
Stores v at index i in place. Only valid when a is exclusive and i is in bounds. Public only
so that uset can be inlined into code in other modules.
Equations
- a.setUnsafe i v = ScalarArray.UInt16Array.mk (a.toArray.uset i v ⋯)
Instances For
For internal use only.
Equations
Instances For
Returns a itself when it is not shared, and a copy otherwise. Logically this is the identity.
It is useful before a run of in-place writes, so that only the first one can copy.
Equations
- a.ensureExclusive = a
Instances For
ensureCapacity and ensureExclusiveWithCapacity when a lacks room for n elements: copies a
with room for exactly max n a.size elements. Out of line so that inlined call sites stay small.
Public only so that those functions can be inlined into code in other modules.
Equations
Instances For
For internal use only.
Equations
- a.ensureCapacityImpl n = if n ≤ (unsafeCast a).capacity.toNat then a else a.ensureCapacityGrowUnsafe n
Instances For
Returns a itself when it has room for n elements, and otherwise a copy with room for exactly
max n a.size elements. Logically this is the identity. Unlike ensureExclusiveWithCapacity, it
does not copy a just because it is shared.
Equations
- a.ensureCapacity n = a
Instances For
For internal use only.
Equations
Instances For
Returns a itself when it is not shared and has room for n elements, and otherwise a single copy
with room for exactly max n a.size elements. Logically this is the identity. It is useful before a
run of in-place writes and pushes, so that none of them copies.
Equations
- a.ensureExclusiveWithCapacity n = a
Instances For
For internal use only.
Instances For
For internal use only.
Equations
- a.toArrayImpl = if a.size < USize.size then ScalarArray.UInt16Array.toArrayImpl.loop✝ a a.usize ⋯ 0 (Array.replicate a.size default) ⋯ else Array.ofFn fun (i : Fin a.size) => a.get ↑i ⋯
Instances For
Case analysis on a UInt16Array as mk a. It is the default for cases and induction.
Equations
- ScalarArray.UInt16Array.casesMk mk a = ⋯ ▸ mk a.toArray
Instances For
An empty array with room for capacity elements before reallocating.
Equations
Instances For
The empty array.
Instances For
Equations
- ScalarArray.UInt16Array.instEmptyCollection = { emptyCollection := ScalarArray.UInt16Array.empty }
Equations
Replaces the element at index i, in place when a is not shared. It compiles to inline C: one
check that a is exclusive, copying it if not, and one store.
Equations
- a.uset i v h = ScalarArray.UInt16Array.mk (a.toArray.uset i v h)
Instances For
For internal use only.
Equations
- a.usetImpl i v x✝ = a.ensureExclusive.setUnsafe i v
Instances For
Replaces the element at index i, in place when a is not shared, like uset.
Equations
- a.set i v h = ScalarArray.UInt16Array.mk (a.toArray.set i v h)
Instances For
For internal use only.
Instances For
The element at index i. Panics if i is out of bounds, and then returns default.
Equations
Instances For
Replaces the element at index i. If i is out of bounds, the array is returned unmodified.
Instances For
Equations
- ScalarArray.UInt16Array.instGetElemNatUInt16LtSize = { getElem := fun (a : ScalarArray.UInt16Array) (i : Nat) (h : i < a.size) => a.get i h }
Equations
- ScalarArray.UInt16Array.instGetElemUSizeUInt16LtNatToNatSize = { getElem := fun (a : ScalarArray.UInt16Array) (i : USize) (h : i.toNat < a.size) => a.uget i h }
For internal use only.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Appends v to a, in place when a is not shared and has room. A full array grows to capacity
2 * capacity + 1, so repeated pushes take amortized constant time.
Equations
- a.push v = ScalarArray.UInt16Array.mk (a.toArray.push v)
Instances For
Appends the elements of b to a, in place when a is not shared and has room.
Instances For
Equations
Copies the elements of src from index srcOff up to, but not including, srcOff + len into
dest starting at index destOff, growing dest if necessary. The copy works in place when dest
is not shared and has room. If exact is false, the capacity is doubled when dest grows.
Equations
- One or more equations did not get rendered due to their size.