Documentation

ScalarArray.UInt32.Basic

Arrays of UInt32: basics #

The type, its model, and the operations compiled to the runtime: reads, writes, push, capacity, append and copySlice.

Arrays of UInt32 values, stored unboxed in a scalar array, 4 bytes per element.

The logical model is an Array UInt32: UInt32Array.mk and UInt32Array.toArray convert between the two. cases and induction split a UInt32Array as mk a.

Instances For
    @[noinline, implemented_by ScalarArray.UInt32Array.Internal.mkImpl]

    The UInt32Array whose elements are a.

    Instances For
      @[noinline]

      The elements of a as an Array UInt32.

      Instances For
        @[extern lean_byte_array_size]

        The number of elements of a.

        Instances For
          @[inline]

          For internal use only.

          Instances For
            @[implemented_by ScalarArray.UInt32Array.Internal.usizeImpl]

            The size of a as a USize. Since USize can address all memory, no array has more elements than USize can count.

            Instances For

              a.usize is at most the size, so it bounds the indices of loops that stop at a.usize.

              @[inline]

              For internal use only.

              Instances For
                @[instance_reducible, implemented_by ScalarArray.UInt32Array.Internal.decSizeLtImpl, instance 10000]

                Decides a.size < USize.size, which holds for every array in memory, as for usize. The safe loops index with USize, so their csimp proofs test the bound, with a fallback for the other case. At runtime this instance is isTrue without a test, so the compiler removes the test and the fallback, which would otherwise cost a Nat comparison and, when the fallback calls a fold, a closure for its function. This is the one unchecked fact behind those proofs.

                @[extern c inline "((uint32_t*)lean_sarray_cptr(#1))[#2]"]
                def ScalarArray.UInt32Array.uget (a : UInt32Array) (i : USize) (h : i.toNat < a.size := by get_elem_tactic) :

                The element at the USize index i. It compiles to an inline load.

                Instances For
                  @[implemented_by ScalarArray.UInt32Array.Internal.getImpl]
                  def ScalarArray.UInt32Array.get (a : UInt32Array) (i : Nat) (h : i < a.size := by get_elem_tactic) :

                  The element at index i.

                  Instances For
                    @[inline]
                    unsafe def ScalarArray.UInt32Array.Internal.getImpl (a : UInt32Array) (i : Nat) (h : i < a.size := by get_elem_tactic) :

                    For internal use only.

                    Instances For
                      @[never_extract, extern c inline "#1;\n((uint32_t*)lean_sarray_cptr(#1))[#2] = #3"]

                      Stores v at index i in place. Only valid when a is exclusive and i is in bounds. Public only so that uset can be inlined into code in other modules.

                      Instances For
                        @[never_extract, inline]

                        For internal use only.

                        Instances For
                          @[never_extract, implemented_by ScalarArray.UInt32Array.Internal.ensureExclusiveImpl]

                          Returns a itself when it is not shared, and a copy otherwise. Logically this is the identity. It is useful before a run of in-place writes, so that only the first one can copy.

                          Instances For
                            @[never_extract]

                            ensureCapacity and ensureExclusiveWithCapacity when a lacks room for n elements: copies a with room for exactly max n a.size elements. Out of line so that inlined call sites stay small. Public only so that those functions can be inlined into code in other modules.

                            Instances For
                              @[inline]

                              For internal use only.

                              Instances For
                                @[never_extract, implemented_by ScalarArray.UInt32Array.Internal.ensureCapacityImpl]

                                Returns a itself when it has room for n elements, and otherwise a copy with room for exactly max n a.size elements. Logically this is the identity. Unlike ensureExclusiveWithCapacity, it does not copy a just because it is shared.

                                Instances For
                                  @[inline]

                                  For internal use only.

                                  Instances For
                                    @[never_extract, implemented_by ScalarArray.UInt32Array.Internal.ensureExclusiveWithCapacityImpl]

                                    Returns a itself when it is not shared and has room for n elements, and otherwise a single copy with room for exactly max n a.size elements. Logically this is the identity. It is useful before a run of in-place writes and pushes, so that none of them copies.

                                    Instances For

                                      For internal use only.

                                      Instances For

                                        For internal use only.

                                        Instances For
                                          def ScalarArray.UInt32Array.casesMk {motive : UInt32Array → Sort u} (mk : (a : Array UInt32) → motive (mk a)) (a : UInt32Array) :
                                          motive a

                                          Case analysis on a UInt32Array as mk a. It is the default for cases and induction.

                                          Instances For
                                            @[implemented_by _private.ScalarArray.UInt32.Basic.0.ScalarArray.UInt32Array.emptyWithCapacityImpl]

                                            An empty array with room for capacity elements before reallocating.

                                            Instances For

                                              The empty array.

                                              Instances For
                                                @[implemented_by ScalarArray.UInt32Array.Internal.usetImpl]
                                                def ScalarArray.UInt32Array.uset (a : UInt32Array) (i : USize) (v : UInt32) (h : i.toNat < a.size := by get_elem_tactic) :

                                                Replaces the element at index i, in place when a is not shared. It compiles to inline C: one check that a is exclusive, copying it if not, and one store.

                                                Instances For
                                                  @[inline]
                                                  unsafe def ScalarArray.UInt32Array.Internal.usetImpl (a : UInt32Array) (i : USize) (v : UInt32) (h : i.toNat < a.size := by get_elem_tactic) :

                                                  For internal use only.

                                                  Instances For
                                                    @[implemented_by ScalarArray.UInt32Array.Internal.setImpl]
                                                    def ScalarArray.UInt32Array.set (a : UInt32Array) (i : Nat) (v : UInt32) (h : i < a.size := by get_elem_tactic) :

                                                    Replaces the element at index i, in place when a is not shared, like uset.

                                                    Instances For
                                                      @[inline]
                                                      unsafe def ScalarArray.UInt32Array.Internal.setImpl (a : UInt32Array) (i : Nat) (v : UInt32) (h : i < a.size := by get_elem_tactic) :

                                                      For internal use only.

                                                      Instances For
                                                        @[inline]

                                                        The element at index i. Panics if i is out of bounds, and then returns default.

                                                        Instances For
                                                          @[inline]

                                                          The element at index i, or v₀ if i is out of bounds.

                                                          Instances For
                                                            @[inline]

                                                            Replaces the element at index i. If i is out of bounds, the array is returned unmodified.

                                                            Instances For

                                                              push when a is full: copies a with capacity 2 * capacity + 1, then appends v. Out of line so that inlined push call sites stay small. Public only so that push can be inlined into code in other modules.

                                                              Instances For
                                                                @[inline]

                                                                For internal use only.

                                                                Instances For
                                                                  @[implemented_by ScalarArray.UInt32Array.Internal.pushImpl]

                                                                  Appends v to a, in place when a is not shared and has room. A full array grows to capacity 2 * capacity + 1, so repeated pushes take amortized constant time.

                                                                  Instances For
                                                                    @[implemented_by _private.ScalarArray.UInt32.Basic.0.ScalarArray.UInt32Array.appendImpl]

                                                                    Appends the elements of b to a, in place when a is not shared and has room.

                                                                    Instances For
                                                                      @[implemented_by _private.ScalarArray.UInt32.Basic.0.ScalarArray.UInt32Array.copySliceImpl]
                                                                      def ScalarArray.UInt32Array.copySlice (src : UInt32Array) (srcOff : Nat) (dest : UInt32Array) (destOff len : Nat) (exact : Bool := true) :

                                                                      Copies the elements of src from index srcOff up to, but not including, srcOff + len into dest starting at index destOff, growing dest if necessary. The copy works in place when dest is not shared and has room. If exact is false, the capacity is doubled when dest grows.

                                                                      Instances For