Equations
- ByteArray.instBEq.beq { data := a } { data := b } = (a == b)
- ByteArray.instBEq.beq x✝¹ x✝ = false
Instances For
Equations
- ByteArray.instBEq = { beq := ByteArray.instBEq.beq }
Equations
Instances For
Equations
- ByteArray.instInhabited = { default := ByteArray.empty }
Equations
- ByteArray.instEmptyCollection = { emptyCollection := ByteArray.empty }
Retrieves the byte at the indicated index. Callers must prove that the index is in bounds. The index is represented by a platform-specific fixed-width integer (either 32 or 64 bits).
Because USize is big enough to address all memory on every platform that Lean supports, there are
in practice no ByteArrays for which uget cannot retrieve all elements.
Instances For
Replaces the byte at the given index.
The array is modified in-place if there are no other references to it.
If the index is out of bounds, the array is returned unmodified.
Instances For
Replaces the byte at the given index.
No bounds check is performed, but the function requires a proof that the index is in bounds. This proof can usually be omitted, and will be synthesized automatically.
The array is modified in-place if there are no other references to it.
Instances For
Replaces the byte at the given index.
No bounds check is performed, but the function requires a proof that the index is in bounds. This proof can usually be omitted, and will be synthesized automatically.
The array is modified in-place if there are no other references to it.
Instances For
Computes a hash for a ByteArray.
Equations
- ByteArray.instHashable = { hash := ByteArray.hash }
Copies the slice at [srcOff, srcOff + len) in src to [destOff, destOff + len) in
dest, growing dest if necessary. If exact is false, the capacity
will be doubled when grown.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Equations
- ByteArray.instAppend = { append := ByteArray.append }
Converts a packed array of bytes to a linked list.
Equations
- bs.toList = ByteArray.toList.loop bs 0 []
Instances For
Finds the index of the first byte in a for which p returns true. If no byte
in a satisfies p, then the result is none.
The index is returned along with a proof that it is a valid index in the array.
Equations
- a.findFinIdx? p start = ByteArray.findFinIdx?.loop a p start
Instances For
Equations
Instances For
Finds the index of the first byte in a for which p returns true. If no byte
in a satisfies p, then the result is none.
The variant findFinIdx? additionally returns a proof that the found index is in bounds.
Equations
- a.findIdx? p start = ByteArray.findIdx?.loop a p start
Instances For
An efficient implementation of ForIn.forIn for ByteArray that uses USize
rather than Nat for indices.
We claim this unsafe implementation is correct because an array cannot have more than
USize.size elements in our runtime. This is similar to the Array version.
Equations
- as.forInUnsafe b f = ByteArray.forInUnsafe.loop as f as.usize 0 b
Instances For
The reference implementation of ForIn.forIn for ByteArray.
In compiled code, this is replaced by the more efficient ByteArray.forInUnsafe.
Equations
- as.forIn b f = ByteArray.forIn.loop as f as.size ⋯ b
Instances For
Equations
- ByteArray.instForInUInt8 = { forIn := fun {β : Type ?u.10} [Monad m] => ByteArray.forIn }
An efficient implementation of a monadic left fold on for ByteArray that uses USize
rather than Nat for indices.
We claim this unsafe implementation is correct because an array cannot have more than
USize.size elements in our runtime. This is similar to the Array version.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A monadic left fold on ByteArray that iterates over an array from low to high indices,
computing a running value.
Each element of the array is combined with the value from the prior elements using a monadic
function f. The initial value init is the starting value before any elements have
been processed.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A left fold on ByteArray that iterates over an array from low to high indices, computing a
running value.
Each element of the array is combined with the value from the prior elements using a function
f. The initial value init is the starting value before any elements have been
processed.
ByteArray.foldlM is a monadic variant of this function.
Equations
- ByteArray.foldl f init as start stop = (ByteArray.foldlM (fun (x1 : β) (x2 : UInt8) => pure (f x1 x2)) init as start stop).run
Instances For
Iterator over the bytes (UInt8) of a ByteArray.
Typically created by arr.iter, where arr is a ByteArray.
An iterator is valid if the position i is valid for the array arr, meaning 0 ≤ i ≤ arr.size
Most operations on iterators return arbitrary values if the iterator is not valid. The functions in
the ByteArray.Iterator API should rule out the creation of invalid iterators, with two exceptions:
Iterator.next iteris invalid ifiteris already at the end of the array (iter.atEndistrue)Iterator.forward iter n/Iterator.nextn iter nis invalid ifnis strictly greater than the number of remaining bytes.
- array : ByteArray
The array the iterator is for.
- idx : Nat
The current position.
This position is not necessarily valid for the array, for instance if one keeps calling
Iterator.nextwhenIterator.atEndis true. If the position is not valid, then the current byte is(default : UInt8).
Instances For
Instances For
Equations
Creates an iterator at the beginning of an array.
Equations
- arr.mkIterator = { array := arr, idx := 0 }
Instances For
Creates an iterator at the beginning of an array.
Equations
Instances For
The size of an array iterator is the number of bytes remaining.
Equations
- ByteArray.instSizeOfIterator = { sizeOf := fun (i : ByteArray.Iterator) => i.array.size - i.idx }
The number of bytes remaining in the iterator.
Instances For
The current position.
This position is not necessarily valid for the array, for instance if one keeps calling
Iterator.next when Iterator.atEnd is true. If the position is not valid, then the
current byte is (default : UInt8).
Instances For
Moves the iterator's position forward by one byte, unconditionally.
It is only valid to call this function if the iterator is not at the end of the array, i.e.
Iterator.atEnd is false; otherwise, the resulting iterator will be invalid.
Instances For
Moves the iterator's position several bytes forward.
The resulting iterator is only valid if the number of bytes to skip is less than or equal to the number of bytes left in the iterator.
Instances For
Moves the iterator's position several bytes forward.
The resulting iterator is only valid if the number of bytes to skip is less than or equal to the number of bytes left in the iterator.