Documentation

Init.Data.ByteArray.Basic

@[extern lean_mk_empty_byte_array]
Equations
@[extern lean_byte_array_push]
Equations
  • { data := bs }.push x✝ = { data := bs.push x✝ }
@[extern lean_byte_array_size]
Equations
@[extern lean_sarray_size]
Equations
@[extern lean_byte_array_uget]
def ByteArray.uget (a : ByteArray) (i : USize) (h : i.toNat < a.size := by get_elem_tactic) :
Equations
  • { data := bs }.uget x✝¹ x✝ = bs[x✝¹]
@[extern lean_byte_array_get]
Equations
@[extern lean_byte_array_fget]
def ByteArray.get (a : ByteArray) (i : Nat) (h : i < a.size := by get_elem_tactic) :
Equations
  • { data := bs }.get x✝¹ x✝ = bs[x✝¹]
Equations
@[extern lean_byte_array_set]
Equations
  • { data := bs }.set! x✝¹ x✝ = { data := bs.set! x✝¹ x✝ }
@[extern lean_byte_array_fset]
def ByteArray.set (a : ByteArray) (i : Nat) :
UInt8(h : autoParam (i < a.size) _auto✝) → ByteArray
Equations
  • { data := bs }.set x✝² x✝¹ x✝ = { data := bs.set x✝² x✝¹ x✝ }
@[extern lean_byte_array_uset]
def ByteArray.uset (a : ByteArray) (i : USize) :
Equations
  • { data := bs }.uset x✝² x✝¹ x✝ = { data := bs.uset x✝² x✝¹ x✝ }
@[extern lean_byte_array_hash]
@[extern lean_byte_array_copy_slice]
def ByteArray.copySlice (src : ByteArray) (srcOff : Nat) (dest : ByteArray) (destOff len : Nat) (exact : 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.
Equations
@[irreducible]
Equations
@[inline]
def ByteArray.findIdx? (a : ByteArray) (p : UInt8Bool) (start : Nat := 0) :
Equations
@[irreducible, specialize #[]]
Equations
@[inline]
def ByteArray.findFinIdx? (a : ByteArray) (p : UInt8Bool) (start : Nat := 0) :
Equations
@[irreducible, specialize #[]]
Equations
@[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
@[specialize #[]]
unsafe def ByteArray.forInUnsafe.loop {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (f : UInt8βm (ForInStep β)) (sz i : USize) (b : β) :
m β
Equations
  • One or more equations did not get rendered due to their size.
@[implemented_by ByteArray.forInUnsafe]
def ByteArray.forIn {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (b : β) (f : UInt8βm (ForInStep β)) :
m β

Reference implementation for forIn

Equations
def ByteArray.forIn.loop {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (f : UInt8βm (ForInStep β)) (i : Nat) (h : i as.size) (b : β) :
m β
Equations
instance ByteArray.instForInUInt8 {m : Type u_1 → Type u_2} :
Equations
@[inline]
unsafe def ByteArray.foldlMUnsafe {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (init : β) (as : ByteArray) (start : Nat := 0) (stop : Nat := as.size) :
m β

See comment at forInUnsafe

Equations
  • One or more equations did not get rendered due to their size.
@[specialize #[]]
unsafe def ByteArray.foldlMUnsafe.fold {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (as : ByteArray) (i stop : USize) (b : β) :
m β
Equations
@[implemented_by ByteArray.foldlMUnsafe]
def ByteArray.foldlM {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (init : β) (as : ByteArray) (start : Nat := 0) (stop : Nat := as.size) :
m β

Reference implementation for foldlM

Equations
  • One or more equations did not get rendered due to their size.
def ByteArray.foldlM.loop {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (as : ByteArray) (stop : Nat) (h : stop as.size) (i j : Nat) (b : β) :
m β
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def ByteArray.foldl {β : Type v} (f : βUInt8β) (init : β) (as : ByteArray) (start : Nat := 0) (stop : Nat := as.size) :
β
Equations

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:

  • 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 when Iterator.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
@[reducible, inline]

Creates an iterator at the beginning of an array.

Equations

The size of an array iterator is the number of bytes remaining.

Equations

Number of bytes remaining in the iterator.

Equations

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).

Equations
@[inline]

The byte at the current position.

On an invalid position, returns (default : UInt8).

Equations
@[inline]

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.

Equations
  • { array := arr, idx := i }.next = { array := arr, idx := i + 1 }
@[inline]

Decreases the iterator's position.

If the position is zero, this function is the identity.

Equations
  • { array := arr, idx := i }.prev = { array := arr, idx := i - 1 }
@[inline]

True if the iterator is past the array's last byte.

Equations
@[inline]

True if the iterator is not past the array's last byte.

Equations
@[inline]

The byte at the current position. -

Equations
  • { array := arr, idx := i }.curr' h_2 = arr[i]
@[inline]

Moves the iterator's position forward by one byte. -

Equations
  • { array := arr, idx := i }.next' h_1 = { array := arr, idx := i + 1 }
@[inline]

True if the position is not zero.

Equations
@[inline]

Moves the iterator's position to the end of the array.

Note that i.toEnd.atEnd is always true.

Equations
  • { array := arr, idx := i }.toEnd = { array := arr, idx := arr.size }
@[inline]

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
  • { array := arr, idx := i }.forward x✝ = { array := arr, idx := i + x✝ }
@[inline]

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
@[inline]

Moves the iterator's position several bytes back.

If asked to go back more bytes than available, stops at the beginning of the array.

Equations
  • { array := arr, idx := i }.prevn x✝ = { array := arr, idx := i - x✝ }

Interpret a ByteArray of size 8 as a little-endian UInt64.

Equations
  • One or more equations did not get rendered due to their size.

Interpret a ByteArray of size 8 as a big-endian UInt64.

Equations
  • One or more equations did not get rendered due to their size.