Documentation

Init.Data.ByteArray.Basic

@[implicit_reducible]
theorem ByteArray.ext_iff {x y : ByteArray} :
x = y x.data = y.data
@[implicit_reducible]
@[implicit_reducible]
@[extern lean_sarray_size]

Retrieves the size of the array as a platform-specific fixed-width integer.

Because USize is big enough to address all memory on every platform that Lean supports, there are in practice no ByteArrays that have more elements that USize can count.

Instances For
    @[extern lean_byte_array_uget]
    def ByteArray.uget (a : ByteArray) (i : USize) (h : i.toNat < a.size := by get_elem_tactic) :

    Retrieves the byte at the indicated index. Callers must prove that the index is in bounds. The index is represented by a platform-specific fixed-width integer (either 32 or 64 bits).

    Because USize is big enough to address all memory on every platform that Lean supports, there are in practice no ByteArrays for which uget cannot retrieve all elements.

    Instances For
      @[extern lean_byte_array_get]

      Retrieves the byte at the indicated index. Panics if the index is out of bounds.

      Instances For
        @[extern lean_byte_array_fget]
        def ByteArray.get (a : ByteArray) (i : Nat) (h : i < a.size := by get_elem_tactic) :

        Retrieves the byte at the indicated index. Callers must prove that the index is in bounds.

        Use uget for a more efficient alternative or get! for a variant that panics if the index is out of bounds.

        Instances For
          @[implicit_reducible]
          @[extern lean_byte_array_set]

          Replaces the byte at the given index.

          The array is modified in-place if there are no other references to it.

          If the index is out of bounds, the array is returned unmodified.

          Instances For
            @[extern lean_byte_array_fset]
            def ByteArray.set (a : ByteArray) (i : Nat) :

            Replaces the byte at the given index.

            No bounds check is performed, but the function requires a proof that the index is in bounds. This proof can usually be omitted, and will be synthesized automatically.

            The array is modified in-place if there are no other references to it.

            Instances For
              @[extern lean_byte_array_uset]

              Replaces the byte at the given index.

              No bounds check is performed, but the function requires a proof that the index is in bounds. This proof can usually be omitted, and will be synthesized automatically.

              The array is modified in-place if there are no other references to it.

              Instances For
                @[extern lean_byte_array_hash]

                Computes a hash for a ByteArray.

                @[implicit_reducible]

                Returns true when s contains zero bytes.

                Instances For
                  @[extern lean_byte_array_copy_slice]
                  def ByteArray.copySlice (src : ByteArray) (srcOff : Nat) (dest : ByteArray) (destOff len : Nat) (exact : Bool := true) :

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

                  Instances For

                    Copies the bytes with indices b (inclusive) to e (exclusive) to a new ByteArray.

                    Instances For
                      @[inline]

                      Appends two byte arrays using fast array primitives instead of converting them into lists and back.

                      In compiled code, this function replaces calls to ByteArray.append.

                      Instances For
                        @[simp]
                        @[implicit_reducible]
                        @[simp]
                        theorem ByteArray.append_eq {a b : ByteArray} :
                        a.append b = a ++ b
                        @[simp]

                        Converts a packed array of bytes to a linked list.

                        Instances For
                          @[irreducible]
                          Instances For
                            @[inline]
                            def ByteArray.findFinIdx? (a : ByteArray) (p : UInt8Bool) (start : Nat := 0) :

                            Finds the index of the first byte in a for which p returns true. If no byte in a satisfies p, then the result is none.

                            The index is returned along with a proof that it is a valid index in the array.

                            Instances For
                              @[irreducible, specialize #[]]
                              Instances For
                                @[inline]
                                def ByteArray.findIdx? (a : ByteArray) (p : UInt8Bool) (start : Nat := 0) :

                                Finds the index of the first byte in a for which p returns true. If no byte in a satisfies p, then the result is none.

                                The variant findFinIdx? additionally returns a proof that the found index is in bounds.

                                Instances For
                                  @[irreducible, specialize #[]]
                                  Instances For
                                    @[inline]
                                    unsafe def ByteArray.forInUnsafe {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (b : β) (f : UInt8βm (ForInStep β)) :
                                    m β

                                    An efficient implementation of ForIn.forIn for ByteArray that uses USize rather than Nat for indices.

                                    We claim this unsafe implementation is correct because an array cannot have more than USize.size elements in our runtime. This is similar to the Array version.

                                    Instances For
                                      @[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 β
                                      Instances For
                                        @[implemented_by ByteArray.forInUnsafe]
                                        def ByteArray.forIn {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (b : β) (f : UInt8βm (ForInStep β)) :
                                        m β

                                        The reference implementation of ForIn.forIn for ByteArray.

                                        In compiled code, this is replaced by the more efficient ByteArray.forInUnsafe.

                                        Instances For
                                          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 β
                                          Instances For
                                            @[implicit_reducible]
                                            @[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 β

                                            An efficient implementation of a monadic left fold on for ByteArray that uses USize rather than Nat for indices.

                                            We claim this unsafe implementation is correct because an array cannot have more than USize.size elements in our runtime. This is similar to the Array version.

                                            Instances For
                                              @[specialize #[]]
                                              unsafe def ByteArray.foldlMUnsafe.fold {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (as : ByteArray) (i stop : USize) (b : β) :
                                              m β
                                              Instances For
                                                @[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 β

                                                A monadic left fold on ByteArray that iterates over an array from low to high indices, computing a running value.

                                                Each element of the array is combined with the value from the prior elements using a monadic function f. The initial value init is the starting value before any elements have been processed.

                                                Instances For
                                                  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 β
                                                  Instances For
                                                    @[inline]
                                                    def ByteArray.foldl {β : Type v} (f : βUInt8β) (init : β) (as : ByteArray) (start : Nat := 0) (stop : Nat := as.size) :
                                                    β

                                                    A left fold on ByteArray that iterates over an array from low to high indices, computing a running value.

                                                    Each element of the array is combined with the value from the prior elements using a function f. The initial value init is the starting value before any elements have been processed.

                                                    ByteArray.foldlM is a monadic variant of this function.

                                                    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:

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

                                                        Instances For
                                                          @[reducible, inline]

                                                          Creates an iterator at the beginning of an array.

                                                          Instances For
                                                            @[implicit_reducible]

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

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

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

                                                                Instances For
                                                                  @[inline]

                                                                  The byte at the current position.

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

                                                                  Instances For
                                                                    @[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.

                                                                    Instances For
                                                                      @[inline]

                                                                      Decreases the iterator's position.

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

                                                                      Instances For
                                                                        @[inline]

                                                                        True if the iterator is valid; that is, it is not past the array's last byte.

                                                                        Instances For
                                                                          @[inline]

                                                                          The byte at the current position. -

                                                                          Instances For
                                                                            @[inline]

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

                                                                            Instances For
                                                                              @[inline]

                                                                              True if the position is not zero.

                                                                              Instances For
                                                                                @[inline]

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

                                                                                Given i : ByteArray.Iterator, note that i.toEnd.atEnd is always true.

                                                                                Instances For
                                                                                  @[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.

                                                                                  Instances For
                                                                                    @[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.

                                                                                    Instances For
                                                                                      @[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.

                                                                                      Instances For
                                                                                        @[implicit_reducible]