This module defines the ByteSlice structure. It's a modified version of the SubArray code,
with some functions specific to ByteSlice.
Internal representation of ByteSlice, which is an abbreviation for Slice ByteSliceData.
- byteArray : ByteArray
The underlying byte array.
- start : Nat
The starting index of the region of interest (inclusive).
- stop : Nat
The ending index of the region of interest (exclusive).
The starting index is no later than the ending index.
The ending index is exclusive. If the starting and ending indices are equal, then the byte slice is empty.
The stopping index is no later than the end of the byte array.
The ending index is exclusive. If it is equal to the size of the byte array, then the last byte of the byte array is in the byte slice.
Instances For
A region of some underlying byte array.
A byte slice contains a byte array together with the start and end indices of a region of interest.
Byte slices can be used to avoid copying or allocating space, while being more convenient than
tracking the bounds by hand. The region of interest consists of every index that is both greater
than or equal to start and strictly less than stop.
Equations
Instances For
The underlying byte array.
Equations
Instances For
The starting index of the region of interest (inclusive).
Equations
Instances For
The ending index of the region of interest (exclusive).
Equations
Instances For
Computes the size of the byte slice.
Equations
Instances For
Extracts a byte from the byte slice, or returns a default value v₀ when the index is out of
bounds.
The index is relative to the start and end of the byte slice, rather than the underlying byte array.
Equations
Instances For
Extracts a byte from the byte slice, or returns a default value when the index is out of bounds.
The index is relative to the start and end of the byte slice, rather than the underlying byte array. The default value is 0.
Equations
Instances For
The empty byte slice.
This empty byte slice is backed by an empty byte array.
Equations
Instances For
Creates a new ByteSlice of a ByteArray
Equations
Instances For
Converts a byte slice back to a byte array by copying the relevant portion.
Equations
Instances For
Comparison function
Equations
Instances For
Folds a monadic operation from right to left over the bytes in a byte slice.
An accumulator of type β is constructed by starting with init and monadically combining each
byte of the byte slice with the current accumulator value in turn, moving from the end to the
start. The monad in question may permit early termination or repetition.
Examples:
#eval (ByteArray.mk #[1, 2, 3]).toByteSlice.foldrM (init := 0) fun x acc =>
some x.toNat + acc
some 6
Equations
Instances For
Folds an operation from right to left over the bytes in a byte slice.
An accumulator of type β is constructed by starting with init and combining each byte of the
byte slice with the current accumulator value in turn, moving from the end to the start.
Examples:
(ByteArray.mk #[1, 2, 3]).toByteSlice.foldr (·.toNat + ·) 0 = 6(ByteArray.mk #[1, 2, 3]).toByteSlice.popFront.foldr (·.toNat + ·) 0 = 5
Equations
Instances For
Creates a sub-slice of the byte slice with the given bounds.
If start or stop are not valid bounds for a sub-slice, then they are clamped to the slice's size.
Additionally, the starting index is clamped to the ending index.
The indices are relative to the current slice, not the underlying byte array.
Equations
Instances For
Checks if the byte slice contains a specific byte value.
Returns true if any byte in the slice equals the given value, false otherwise.