Equations
- ByteArray.mkEmpty c = { data := #[] }
Equations
- ByteArray.instInhabited = { default := ByteArray.empty }
Equations
- ByteArray.instEmptyCollection = { emptyCollection := ByteArray.empty }
Equations
- ByteArray.instHashable = { hash := ByteArray.hash }
Copy 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.
Equations
- a.extract b e = a.copySlice b ByteArray.empty 0 (e - b)
Equations
- ByteArray.instAppend = { append := ByteArray.append }
Equations
- bs.toList = ByteArray.toList.loop bs 0 []
Equations
- a.findFinIdx? p start = ByteArray.findFinIdx?.loop a p start
We claim this unsafe implementation is correct because an array cannot have more than usizeSz
elements in our runtime.
This is similar to the Array
version.
TODO: avoid code duplication in the future after we improve the compiler.
Equations
- as.forInUnsafe b f = ByteArray.forInUnsafe.loop as f as.usize 0 b
Equations
- ByteArray.instForInUInt8 = { forIn := fun {β : Type ?u.15} [Monad m] => ByteArray.forIn }
Reference implementation for foldlM
Equations
- One or more equations did not get rendered due to their size.
Equations
- ByteArray.foldl f init as start stop = (ByteArray.foldlM f init as start stop).run
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 iter
is invalid ifiter
is already at the end of the array (iter.atEnd
istrue
)Iterator.forward iter n
/Iterator.nextn iter n
is invalid ifn
is 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.next
whenIterator.atEnd
is true. If the position is not valid, then the current byte is(default : UInt8)
.
Equations
- ByteArray.instInhabitedIterator = { default := { array := default, idx := default } }
Creates an iterator at the beginning of an array.
Equations
- arr.mkIterator = { array := arr, idx := 0 }
Creates an iterator at the beginning of an array.
Equations
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 }
Number of bytes remaining in the iterator.
Equations
- { array := arr, idx := i }.remainingBytes = arr.size - i
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)
.
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.
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.
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.
Equations
Equations
- List.toByteArray.loop [] x✝ = x✝
- List.toByteArray.loop (b :: bs) x✝ = List.toByteArray.loop bs (x✝.push b)
Equations
- instToStringByteArray = { toString := fun (bs : ByteArray) => bs.toList.toString }