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.
Equations
Instances For
Returns the first minimal element among d
and elements of the array.
If start
and stop
are given, only the subarray xs[start:stop]
is
considered (in addition to d
).
Equations
Instances For
Find the first minimal element of an array. If the array is empty, d
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
Instances For
Find the first minimal element of an array. If the array is empty, none
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
Instances For
Find the first minimal element of an array. If the array is empty, default
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Instances For
Returns the first maximal element among d
and elements of the array.
If start
and stop
are given, only the subarray xs[start:stop]
is
considered (in addition to d
).
Instances For
Find the first maximal element of an array. If the array is empty, default
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Instances For
Alias of Array.flatten
.
Appends the contents of array of arrays into a single array. The resulting array contains the same elements as the nested arrays in the same order.
Examples:
#[#[5], #[4], #[3, 2]].flatten = #[5, 4, 3, 2]
#[#[0, 1], #[], #[2], #[1, 0, 1]].flatten = #[0, 1, 2, 1, 0, 1]
(#[] : Array Nat).flatten = #[]
Equations
Instances For
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.
Instances For
Alias of Array.swap
.
Swaps two elements of an array. The modification is performed in-place when the reference to the array is unique.
Examples:
#["red", "green", "blue", "brown"].swap 0 3 = #["brown", "green", "blue", "red"]
#["red", "green", "blue", "brown"].swap 0 2 = #["blue", "green", "red", "brown"]
#["red", "green", "blue", "brown"].swap 1 2 = #["red", "blue", "green", "brown"]
#["red", "green", "blue", "brown"].swap 3 0 = #["brown", "green", "blue", "red"]
Equations
Instances For
Alias of Array.swapAt
.
Swaps a new element with the element at the given index.
Returns the value formerly found at i
, paired with an array in which the value at i
has been
replaced with v
.
Examples:
#["spinach", "broccoli", "carrot"].swapAt 1 "pepper" = ("broccoli", #["spinach", "pepper", "carrot"])
#["spinach", "broccoli", "carrot"].swapAt 2 "pepper" = ("carrot", #["spinach", "broccoli", "pepper"])
Equations
Instances For
Alias of Array.eraseIdx
.
Removes the element at a given index from an array without a run-time bounds check.
This function takes worst-case O(n)
time because it back-shifts all elements at positions
greater than i
.
Examples:
#["apple", "pear", "orange"].eraseIdx 0 = #["pear", "orange"]
#["apple", "pear", "orange"].eraseIdx 1 = #["apple", "orange"]
#["apple", "pear", "orange"].eraseIdx 2 = #["apple", "pear"]
Equations
Instances For
Check whether a subarray contains an element.
Equations
- as.contains a = Subarray.any (fun (x : α) => x == a) as