Definitions on Arrays #
This file contains various definitions on Array
. It does not contain
proofs about these definitions, those are contained in other files in Batteries.Data.Array
.
Check whether xs
and ys
are equal as sets, i.e. they contain the same
elements when disregarding order and duplicates. O(n*m)
! If your element type
has an Ord
instance, it is asymptotically more efficient to sort the two
arrays, remove duplicates and then compare them elementwise.
Alias of Array.flatten
.
Joins array of array into a single array.
flatten #[#[a₁, a₂, ⋯], #[b₁, b₂, ⋯], ⋯]
= #[a₁, a₂, ⋯, b₁, b₂, ⋯]
Equations
Safe Nat Indexed Array functions #
The functions in this section offer variants of Array functions which use Nat
indices
instead of Fin
indices. All these functions have as parameter a proof that the index is
valid for the array. But this parameter has a default argument by get_elem_tactic
which
should prove the index bound.
setN a i h x
sets an element in a vector using a Nat index which is provably valid.
A proof by get_elem_tactic
is provided as a default argument for h
.
This will perform the update destructively provided that a
has a reference count of 1 when called.
Alias of Array.swap
.
Swaps two entries in an array.
This will perform the update destructively provided that a
has a reference
count of 1 when called.
Equations
Alias of Array.swapAt
.
Equations
Alias of Array.eraseIdx
.
Remove the element at a given index from an array without a runtime bounds checks,
using a Nat
index and a tactic-provided bound.
This function takes worst case O(n) time because
it has to backshift all elements at positions greater than i
.
Equations
Check whether a subarray contains an element.
Equations
- as.contains a = Subarray.any (fun (x : α) => x == a) as