std/static_array
import std/static_array to use it. Source: src/std/static_array.iyi at v0.18.0.
A fixed-size array on the stack: StaticArray(T, N).
StaticArrayalias
pub alias StaticArray = ::StaticArrayStaticArray(T, N)struct, reopened
struct ::StaticArray(T, N)
# Comparison based on lexicographical element order. Written out here: it
# forwarded to `Slice#<=>`, which the slice module does not have, so any
# call of this method failed to compile.
def <=>(other : StaticArray(T, N)) : Int32
# Equality. Returns true if corresponding elements are equal, where one
# element type holds the other, as tuples compare (src/iyi/object.iyi).
# Restricted to `StaticArray(T, N)`, a `StaticArray(Int32, 2)` was taken
# for a `StaticArray(Int32?, 2)` and not back: the one equality answered
# true one way and false the other.
def ==(other : StaticArray(U, M)) : Bool forall U, M
def ==(other : Object) : Bool
# Returns the element at the given *index*. Negative indices count backward.
def [](index : Int) : T
# Sets the element at *index* to *value*.
def []=(index : Int, value : T) : T
# Returns the element at *index*, or nil if out of bounds.
def []?(index : Int) : T | ::Nil
def all? : Bool
def any? : Bool
def clone : self
def count(item) : Int32
def count : Int32
# Duplicates this static array.
def dup : self
# Yields each element in order.
def each(& : (T -> Nil)) : Nil
# Yields each element alongside its index.
def each_with_index(offset : Int = 0, & : (T, Int32 -> Nil)) : Nil
# Returns true when the static array contains zero elements.
def empty? : Bool
# Fills *count* elements starting at *start* with *value*.
#
# A negative count and a start outside are refused before anything is
# filled, as the other library and `Slice#fill` refuse them: an early
# return for `c <= 0` came first, so `fill(7, 0, -1)` and `fill(7, 9, 0)`
# of four elements answered the array untouched and said nothing.
def fill(value : T, start : Int, count : Int) : self
# Fills the entire static array with *value*.
def fill(value : T) : self
# Returns the first element. Raises if empty.
def first : T
# Returns the first element or nil if empty.
def first? : T | ::Nil
# Hashing follows the `==` above, mixed as `Array#hash` mixes. There was
# only the other library's `hash(hasher)`, which no table here calls, so
# `Object#hash` answered the type's id: every `StaticArray(Int32, 2)` was
# one slot, and 40,000 of them took 13 s to insert where the same pairs
# as tuples took 3 ms.
def hash : Int32
# Returns true if *object* is in the array.
def includes?(object) : Bool
# Returns the index of *object*, or nil if not found.
def index(object, offset : Int = 0) : Int32 | ::Nil
def inspect(io : IO) : Nil
def inspect : String
# Returns the last element. Raises if empty.
def last : T
# Returns the last element or nil if empty.
def last? : T | ::Nil
# Returns a new StaticArray with mapped elements.
def map(&block : (T -> U)) : StaticArray(U, N) forall U
# Returns a new StaticArray with mapped elements and indices.
def map_with_index(offset : Int = 0, &block : (T, Int32 -> U)) : StaticArray(U, N) forall U
# Creates a new StaticArray filled by invoking the block for each index.
def self.new(& : (Int32 -> T)) : self
# Creates a new StaticArray filled with the given value.
def self.new(value : T) : self
def none? : Bool
def one? : Bool
# Yields elements in reverse order.
def reverse_each(& : (T -> Nil)) : Nil
# Reverses elements in place.
def reverse_in_place : self
# Returns the last index of *object*, or nil if not found.
def rindex(object, offset : Int = N - 1) : Int32 | ::Nil
# Rotates elements in place by *n* positions. Reduced in `Int64` before it
# is narrowed, as `index_within` and `BitArray`'s rotation count: `n.to_i`
# panicked "arithmetic overflow" for 3000000001_i64, which rotates four
# elements by one.
def rotate_in_place(n : Int = 1) : self
# Returns the size of self.
def size : Int32
# Returns a new sorted static array.
def sort : StaticArray(T, N)
def sort(&block : (T, T -> Int32)) : StaticArray(T, N)
def sort_by(&block : (T -> _)) : StaticArray(T, N)
# Each key computed once, by `Array#sort_in_place_by`, the merge sort of
# key and element pairs: a comparison of `yield(a) <=> yield(b)` computed
# it twice per comparison, 63,992,000 times for 8,000 elements.
def sort_by_in_place(&block : (T -> _)) : self
# Sorted by `Array#sort_in_place`, the stable merge sort, and copied
# back. It was an insertion sort of its own, quadratic: 8,000 elements in
# reverse order took 31,996,000 comparisons where the array's sort takes
# under 100,000. Equal elements keep their order, as they did.
def sort_in_place : self
# In-place sort with custom block comparator, by the same merge sort.
def sort_in_place(&block : (T, T -> Int32)) : self
# Converts this static array into a heap Array.
def to_a : Array(T)
# The text `to_s` builds, written as `BitArray#to_s(io)` writes it. It
# asked each element for `inspect(io)`, which no prelude type has, and
# `IyiIO` for `<<`, which only `import std/io` gives it: `to_s(STDOUT)`
# of a `StaticArray(Int32, 3)` did not compile, and `inspect(io)` with it.
def to_s(io : IO) : Nil
# Into one builder: adding each element to the text so far copied that
# text once per element, and 10,000 elements took 1.4 s where `to_a.to_s`
# of the same took 1 ms.
def to_s : String
# Returns a Slice backed by this static array.
def to_slice : Std::Slice::Slice(T)
# Returns a pointer to this static array's data.
def to_unsafe : Pointer(T)
# Returns the element at *index* without bounds checking.
def unsafe_fetch(index : Int) : T
# Sets the element at *index* to *value* without bounds checking.
def unsafe_put(index : Int, value : T) : T
def unstable_sort : StaticArray(T, N)
def unstable_sort(&block : (T, T -> Int32)) : StaticArray(T, N)
def unstable_sort_by(&block : (T -> _)) : StaticArray(T, N)
def unstable_sort_by_in_place(&block : (T -> _)) : self
def unstable_sort_in_place : self
def unstable_sort_in_place(&block : (T, T -> Int32)) : self
macro [](*args)
end
Fixed-size stack-allocated array for iyi.