Array
Array module: persistent vector backed by a 32-way trie.
PersistentVector(a) is an immutable, indexed sequential collection. The trie has branching factor 32 (5-bit chunks of the index path).
A tail buffer holds the rightmost (up to 32) elements outside the trie. Appending to the tail is O(1); when it fills to 32 it is flushed into the trie (O(log₃₂ n)).
Complexity (n elements): get / set O(log₃₂ n) ≈ O(1) push O(1) amortized pop O(1) amortized length O(1) from_list / fold O(n)
Types
Functions
Returns an empty persistent vector.
Returns the number of elements. O(1).
Returns true if the vector is empty.
Returns the element at index idx (0-based). O(log₃₂ n). Panics if idx is out of range.
Returns a new vector with element at idx replaced by val. O(log₃₂ n). Panics if idx is out of range.
Appends an element at the end. O(1) amortized.
Removes the last element. Returns (new_vector, last_element). Panics if the vector is empty.
Applies f to each element, returning a new vector with the results. O(n).
Left fold over all elements in index order. f(acc, elem) = new_acc.
Returns all elements as a list in index order. O(n).
Builds a persistent vector from a list. O(n).