Documentation

Init.Data.ByteArray.Basic

structure ByteArray :
Instances For
    @[extern lean_mk_empty_byte_array]
    Equations
    Instances For
      @[extern lean_byte_array_push]
      Equations
      • { data := bs }.push x = { data := bs.push x }
      Instances For
        @[extern lean_byte_array_size]
        Equations
        • { data := bs }.size = bs.size
        Instances For
          @[extern lean_sarray_size]
          Equations
          • a.usize = a.size.toUSize
          Instances For
            @[extern lean_byte_array_uget]
            def ByteArray.uget (a : ByteArray) (i : USize) :
            i.toNat < a.sizeUInt8
            Equations
            • { data := bs }.uget x✝ x = bs[x✝]
            Instances For
              @[extern lean_byte_array_get]
              Equations
              • { data := bs }.get! x = bs.get! x
              Instances For
                @[extern lean_byte_array_fget]
                def ByteArray.get (a : ByteArray) :
                Fin a.sizeUInt8
                Equations
                • { data := bs }.get i = bs.get i
                Instances For
                  Equations
                  Equations
                  @[extern lean_byte_array_set]
                  Equations
                  • { data := bs }.set! x✝ x = { data := bs.set! x✝ x }
                  Instances For
                    @[extern lean_byte_array_fset]
                    def ByteArray.set (a : ByteArray) :
                    Fin a.sizeUInt8ByteArray
                    Equations
                    • { data := bs }.set i x = { data := bs.set i x }
                    Instances For
                      @[extern lean_byte_array_uset]
                      def ByteArray.uset (a : ByteArray) (i : USize) :
                      UInt8i.toNat < a.sizeByteArray
                      Equations
                      • { data := bs }.uset x✝¹ x✝ x = { data := bs.uset x✝¹ x✝ x }
                      Instances For
                        @[extern lean_byte_array_hash]
                        Equations
                        • s.isEmpty = (s.size == 0)
                        Instances For
                          @[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
                            Instances For
                              Equations
                              • a.append b = b.copySlice 0 a a.size b.size false
                              Instances For
                                Equations
                                Instances For
                                  @[irreducible]
                                  Equations
                                  Instances For
                                    @[inline]
                                    def ByteArray.findIdx? (a : ByteArray) (p : UInt8Bool) (start : optParam Nat 0) :
                                    Equations
                                    Instances For
                                      @[irreducible, specialize #[]]
                                      Equations
                                      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.

                                        Instances For
                                          @[specialize #[]]
                                          unsafe def ByteArray.forInUnsafe.loop {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (f : UInt8βm (ForInStep β)) (sz : USize) (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 β

                                            Reference implementation for forIn

                                            Equations
                                            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 β
                                              Equations
                                              Instances For
                                                instance ByteArray.instForInUInt8 {m : Type u_1 → Type u_2} :
                                                Equations
                                                • ByteArray.instForInUInt8 = { forIn := fun {β : Type ?u.14} [Monad m] => ByteArray.forIn }
                                                @[inline]
                                                unsafe def ByteArray.foldlMUnsafe {β : Type v} {m : Type v → Type w} [Monad m] (f : βUInt8m β) (init : β) (as : ByteArray) (start : optParam Nat 0) (stop : optParam Nat as.size) :
                                                m β

                                                See comment at forInUnsafe

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

                                                            Creates an iterator at the beginning of an array.

                                                            Equations
                                                            • arr.mkIterator = { array := arr, idx := 0 }
                                                            Instances For
                                                              @[reducible, inline]

                                                              Creates an iterator at the beginning of an array.

                                                              Equations
                                                              Instances For

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

                                                                Equations
                                                                theorem ByteArray.Iterator.sizeOf_eq (i : ByteArray.Iterator) :
                                                                sizeOf i = i.array.size - i.idx

                                                                Number of bytes remaining in the iterator.

                                                                Equations
                                                                • { array := arr, idx := i }.remainingBytes = arr.size - i
                                                                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).

                                                                  Equations
                                                                  Instances For
                                                                    @[inline]

                                                                    The byte at the current position.

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

                                                                    Equations
                                                                    • { array := arr, idx := i }.curr = if h : i < arr.size then arr[i] else default
                                                                    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.

                                                                      Equations
                                                                      • { array := arr, idx := i }.next = { array := arr, idx := i + 1 }
                                                                      Instances For
                                                                        @[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 }
                                                                        Instances For
                                                                          @[inline]

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

                                                                          Equations
                                                                          • { array := arr, idx := i }.atEnd = decide (i arr.size)
                                                                          Instances For
                                                                            @[inline]

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

                                                                            Equations
                                                                            • { array := arr, idx := i }.hasNext = decide (i < arr.size)
                                                                            Instances For
                                                                              @[inline]

                                                                              The byte at the current position. -

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

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

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

                                                                                  True if the position is not zero.

                                                                                  Equations
                                                                                  • { array := arr, idx := i }.hasPrev = decide (i > 0)
                                                                                  Instances For
                                                                                    @[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 }
                                                                                    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.

                                                                                      Equations
                                                                                      • { array := arr, idx := i }.forward x = { array := arr, idx := i + x }
                                                                                      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.

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

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

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

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

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

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