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.
Instances For
Equations
- a.extract b e = a.copySlice b ByteArray.empty 0 (e - b)
Instances For
Equations
- ByteArray.toList.loop bs i r = if i < bs.size then ByteArray.toList.loop bs (i + 1) (bs.get! i :: r) else r.reverse
Instances For
Equations
- a.findFinIdx? p start = ByteArray.findFinIdx?.loop a p start
Instances For
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.
Instances For
Reference implementation for foldlM
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- ByteArray.foldl f init as start stop = (ByteArray.foldlM f 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 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)
.
Instances For
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.
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 }
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
The byte at the current position.
On an invalid position, returns (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
Decreases the iterator's position.
If the position is zero, this function is the identity.
Instances For
True if the iterator is past the array's last byte.
Instances For
True if the iterator is not past the array's last byte.
Instances For
The byte at the current position. -
Instances For
Moves the iterator's position forward by one byte. -
Instances For
True if the position is not zero.
Instances For
Moves the iterator's position to the end of the array.
Note that i.toEnd.atEnd
is always true
.
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.
Instances For
Moves the iterator's position several bytes back.
If asked to go back more bytes than available, stops at the beginning of the array.
Instances For
Equations
- List.toByteArray.loop [] x = x
- List.toByteArray.loop (b :: bs) x = List.toByteArray.loop bs (x.push b)
Instances For
Equations
- instToStringByteArray = { toString := fun (bs : ByteArray) => bs.toList.toString }