Skip to content

stdlib.array

Fixed-Size Array Operations

Generated from v0.60.1. 3 source files, 44 documented symbols.

array.xi

fn len[T, N](arr: &[N]T) -> Int

Number of elements in the fixed-size array.

fn is_empty[T, N](arr: &[N]T) -> Bool

True when the array has zero length.

fn first[T, N](arr: &[N]T) -> Option[T]

First element, or None for an empty array.

  • Postcondition: N == 0 => result is None

fn last[T, N](arr: &[N]T) -> Option[T]

Last element, or None for an empty array.

  • Postcondition: N == 0 => result is None

fn get[T, N](arr: &[N]T, index: Int) -> Option[T]

Element at index, or None when out of bounds.

  • Postcondition: index < 0 || index >= N => result is None

fn get_mut[T, N](arr: &mut [N]T, index: Int) -> Option[T]

Value-returning read (like Vec.get). The Option<&T> reference form is not representable on this compiler: the mono'd body boxes the element VALUE into the Option payload while call sites auto-deref the payload as a pointer (inttoptr of the value -> AV). All consumers must use the value form.

  • Postcondition: index < 0 || index >= N => result is None

fn map[T, U, N](arr: [N]T, f: fn(T) -> U) -> [N]U

Apply f to every element, returning a new array.

fn zip[T, U, N](a: [N]T, b: [N]U) -> [N](T, U)

Pair the elements of two arrays positionally.

fn fold[T, B, N](arr: [N]T, init: B, f: fn(B, T) -> B) -> B

Fold the elements with f, starting from init.

fn as_slice[T, N](arr: &[N]T) -> Slice[T]

Borrow the array as a Slice.

  • Precondition: N > 0
  • Postcondition: result.len == N

fn as_mut_slice[T, N](arr: &mut [N]T) -> Slice[T]

Mutably borrow the array as a Slice.

  • Precondition: N > 0
  • Postcondition: result.len == N

fn each_ref[T, N](arr: &[N]T) -> [N]&T

Array of shared references to each element.

fn each_mut[T, N](arr: &mut [N]T) -> [N]&mut T

Array of mutable references to each element.

fn fill[T, N](arr: &mut [N]T, value: T)

Set every element to a clone of value.

  • Postcondition: true

fn swap[T, N](arr: &mut [N]T, a: Int, b: Int)

Swap the elements at a and b.

  • Precondition: a >= 0 && a < N
  • Precondition: b >= 0 && b < N

fn reverse[T, N](arr: &mut [N]T)

Reverse the elements in place.

  • Postcondition: true

fn rotate_left[T, N](arr: &mut [N]T, mid: Int)

Rotate the elements left by mid positions.

  • Precondition: mid >= 0
  • Precondition: mid <= N

fn rotate_right[T, N](arr: &mut [N]T, k: Int)

Rotate the elements right by k positions.

  • Precondition: k >= 0

fn sort[T, N](arr: &mut [N]T)

Sort the elements in place (ascending).

  • Postcondition: arr.is_sorted()

fn sort_by[T, N](arr: &mut [N]T, compare: fn(&T, &T) -> Ordering)

Sort with a comparator returning an Ordering.

  • Postcondition: arr.is_sorted_by(compare)

fn binary_search[T, N](arr: &[N]T, x: &T) -> Result[Int, Int]

Binary search in a sorted array: Ok(index) or Err(insertion point).

  • Precondition: N >= 0
  • Precondition: arr.is_sorted()

fn contains[T, N](arr: &[N]T, x: &T) -> Bool

True when the array contains x.

  • Postcondition: result == true => arr.contains(x)

fn array_sum[N](arr: &[N]Int) -> Int

Sum of all elements in an integer array. O(N).

fn array_max[T, N](arr: &[N]T) -> Option[T]

Maximum element in an array, or None if N == 0. O(N).

fn array_min[T, N](arr: &[N]T) -> Option[T]

Minimum element in an array, or None if N == 0. O(N).

fn array_count[T, N](arr: &[N]T, value: T) -> Int

Count occurrences of value in the array. O(N).

fn array_find[T, N](arr: &[N]T, value: T) -> Option[Int]

Find the index of the first occurrence of value, or None. O(N).

fn array_equal[T, N](a: &[N]T, b: &[N]T) -> Bool

Deep equality check between two arrays. O(N).



dynamic.xi

fn array_push(a: &mut Vec[Int], value: Int)

Append value to the end of a. O(1) amortized.

fn array_pop(a: &mut Vec[Int]) -> Option[Int]

Remove and return the last element, or None if a is empty. O(1).

fn array_insert(a: &mut Vec[Int], idx: Int, value: Int)

Insert value at idx, shifting later elements right. O(n). No-op when idx is outside [0, len].

fn array_remove(a: &mut Vec[Int], idx: Int) -> Option[Int]

Remove and return the element at idx, or None if out of bounds. O(n).

fn array_resize(a: &mut Vec[Int], n: Int, fill: Int)

Resize a to n elements, padding new slots with fill. O(n). Negative n is a no-op; shrinking drops trailing elements.

fn array_concat(a: &Vec[Int], b: &Vec[Int]) -> Vec[Int]

New vector with a followed by b. O(a.len() + b.len()).

fn array_extend(a: &mut Vec[Int], b: &Vec[Int])

Append all elements of b to a. O(b.len()).

fn array_sort(a: &mut Vec[Int])

Sort a in place. O(n log n), stable, O(n) space.

fn array_search(a: &Vec[Int], item: Int) -> Option[Int]

Index of the first occurrence of item, or None. O(n).

fn array_is_empty(a: &Vec[Int]) -> Bool

True if the vector has no elements. O(1).




fixed.xi

fn array_len[N](a: &[N]Int) -> Int

Compile-time length N of a fixed-size array. O(1).

fn array_get[N](a: &[N]Int, idx: Int) -> Option[Int]

Element at idx, or None if out of bounds. O(1). Returns a value copy.

fn array_first[N](a: &[N]Int) -> Option[Int]

First element, or None if N == 0. O(1).

fn array_last[N](a: &[N]Int) -> Option[Int]

Last element, or None if N == 0. O(1).

fn array_slice[N](a: &[N]Int, start: Int, end: Int) -> Vec[Int]

Copy of a[start..end) as a Vec[Int]. Bounds are clamped to [0, N]. O(n).

fn array_zip[N, M](a: &[N]Int, b: &[N]Int) -> Vec[(Int, Int)]

(a[i], b[i]) pairs, truncated to the shorter array. O(min(N, M)). Returns Vec[(Int, Int)].