← Standard library

Array

sealed class Array<T>
import Array from Wax;

Fixed-length, dense storage, created with new T[n] or an array initializer. All readable slots contain values; reference elements without a default require initialization. Indexing and slices are bounds-checked. Spans borrow storage, while copied reference elements continue to refer to the same objects. Sorting and filling mutate the array.

Array.wax:13

Inherits from object. Follow these links for inherited members.

Members

sizefield

public native readonly int32 size

The number of live elements; valid element indices are [0, size). Capacity is not part of the readable range.

Array.wax:26

thisindexer-getter

public get this(int32 index) : T

Reads or replaces a live element at a zero-based index. An index outside [0, size) panics. Replacing an element does not change the collection size.

Array.wax:36

thisindexer-setter

public set this(int32 index, T value) : void

Reads or replaces a live element at a zero-based index. An index outside [0, size) panics. Replacing an element does not change the collection size.

Array.wax:41

ToSpanmethod

public fn ToSpan() : Span<T>

Borrows a mutable view of the current live elements without copying. The view has a fixed length. Writes affect shared storage; it does not follow a later collection reallocation.

Array.wax:47

ToWriteOnlySpanmethod

public fn ToWriteOnlySpan() : WriteOnlySpan<T>

Borrows a write-only view of the live element range without copying. Writes change the backing storage; the view itself cannot read values.

Array.wax:53

ToReadOnlySpanmethod

public fn ToReadOnlySpan() : ReadOnlySpan<T>

Borrows the current live elements without copying or permitting writes through this view. Other aliases can still mutate the storage; the view does not follow a later reallocation.

Array.wax:61

Emptygetter

public static get Empty() : T[]

Returns the shared zero-length array of this element type.

Array.wax:71

Slicemethod

public fn Slice(int32 start, int32 len) : Span<T>

Borrows a mutable window [start, start + len). Negative arguments or a range outside the live elements panic. An empty slice at size is valid.

Array.wax:79

Sortmethod

public fn Sort() : void where T is Comparable

Sorts elements ascending in place using CompareTo. Equal elements have unspecified relative order; use SortStable when order among ties matters. No scratch array is allocated.

Array.wax:90

SortBymethod

public fn SortBy(fn<(T,T) : int32> compare) : void

Sorts in place using a comparator returning a negative value, zero, or a positive value for less, equal, or greater. The comparator must provide a consistent ordering. Equal elements may be reordered.

Array.wax:99

SortStablemethod

public fn SortStable() : void where T is Comparable

Sorts ascending in place with CompareTo, preserving the original order of equal elements. Larger inputs allocate a scratch array.

Array.wax:109

SortStableBymethod

public fn SortStableBy(fn<(T,T) : int32> compare) : void

Sorts in place with a consistent negative/zero/positive comparator, preserving the original order of equal elements. Larger inputs allocate a scratch array.

Array.wax:117

Containsmethod

public fn Contains(T item) : bool where T is Equatable

Tests whether any element matches using Equals. Returns false for an empty view.

Array.wax:124

IndexOfmethod

public fn IndexOf(T item) : int32 where T is Equatable

Returns the first matching element index using Equals, or -1 when absent, including an empty view.

Array.wax:132

LastIndexOfmethod

public fn LastIndexOf(T item) : int32 where T is Equatable

Returns the last matching element index using Equals, or -1 when absent, including an empty view.

Array.wax:140

Fillmethod

public fn Fill(T value) : void

Assigns value to every element of the backing window. An empty view does nothing. Reference elements all receive the same reference.

Array.wax:148

FillRangemethod

public fn FillRange(T value, int32 start, int32 count) : void

Fills [start, start + count) with value. Both endpoints must lie in [0, size]; invalid endpoints panic before any write. An empty or reversed range whose endpoints are valid performs no writes.

Array.wax:157

CopyTomethod

public fn CopyTo(Span<T> dest) : void

Copies the first min(size, dest.length) elements into dest, safely handling overlapping views. A shorter destination truncates the copy without a panic; any remaining destination elements are unchanged. An empty source or destination does nothing. Reference elements copy their references, not the referenced objects.

Array.wax:167

Reversemethod

public fn Reverse() : void

Reverses element order in the backing window. Empty and one-element views are unchanged. Overlapping views observe the reordered elements.

Array.wax:175

BinarySearchmethod

public fn BinarySearch(T item) : int32 where T is Comparable

Searches a view already sorted ascending under CompareTo. Returns a matching element index; when duplicates exist, the chosen match is unspecified. If absent, returns ~insertionIndex; apply ~ again to recover the insertion position. An empty view returns -1 (~0).

Array.wax:185