Equations
- ByteArray.instInhabited = { default := ByteArray.empty }
Equations
- ByteArray.instEmptyCollection = { emptyCollection := ByteArray.empty }
@[extern lean_byte_array_size]
Equations
- x.size = match x with | { data := bs } => bs.size
Instances For
Equations
- ByteArray.instHashable = { hash := ByteArray.hash }
@[extern lean_byte_array_copy_slice]
def
ByteArray.copySlice
(src : ByteArray)
(srcOff : Nat)
(dest : ByteArray)
(destOff : Nat)
(len : Nat)
(exact : optParam Bool true)
:
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.instAppend = { append := ByteArray.append }
Equations
- bs.toList = ByteArray.toList.loop bs 0 []
Instances For
@[irreducible]
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
@[inline]
unsafe def
ByteArray.forInUnsafe
{β : Type v}
{m : Type v → Type w}
[Monad m]
(as : ByteArray)
(b : β)
(f : UInt8 → β → m (ForInStep β))
:
m β
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 = let sz := as.usize; ByteArray.forInUnsafe.loop as f sz 0 b
Instances For
@[inline]
unsafe def
ByteArray.foldlMUnsafe
{β : Type v}
{m : Type v → Type w}
[Monad m]
(f : β → UInt8 → m β)
(init : β)
(as : ByteArray)
(start : optParam Nat 0)
(stop : optParam Nat as.size)
:
m β
See comment at forInUnsafe
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[specialize #[]]
unsafe def
ByteArray.foldlMUnsafe.fold
{β : Type v}
{m : Type v → Type w}
[Monad m]
(f : β → UInt8 → m β)
(as : ByteArray)
(i : USize)
(stop : USize)
(b : β)
:
m β
Equations
- ByteArray.foldlMUnsafe.fold f as i stop b = if (i == stop) = true then pure b else do let __do_lift ← f b (as.uget i ⋯) ByteArray.foldlMUnsafe.fold f as (i + 1) stop __do_lift
Instances For
@[implemented_by ByteArray.foldlMUnsafe]
def
ByteArray.foldlM
{β : Type v}
{m : Type v → Type w}
[Monad m]
(f : β → UInt8 → m β)
(init : β)
(as : ByteArray)
(start : optParam Nat 0)
(stop : optParam Nat as.size)
:
m β
Reference implementation for foldlM
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
ByteArray.foldl
{β : Type v}
(f : β → UInt8 → β)
(init : β)
(as : ByteArray)
(start : optParam Nat 0)
(stop : optParam Nat as.size)
:
β
Equations
- ByteArray.foldl f init as start stop = (ByteArray.foldlM f init as start stop).run
Instances For
Equations
- bs.toByteArray = List.toByteArray.loop bs ByteArray.empty
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 }