Documentation

ScalarArray.UInt64.Basic

Arrays of UInt64: basics #

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

Arrays of UInt64 values, stored unboxed in a scalar array, 8 bytes per element.

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

Equations
Instances For
    @[noinline, implemented_by ScalarArray.UInt64Array.mkImpl]

    The UInt64Array whose elements are a.

    Equations
    Instances For
      @[extern lean_byte_array_size]

      The number of elements of a.

      Equations
      Instances For
        @[inline]

        For internal use only.

        Equations
        Instances For
          @[implemented_by ScalarArray.UInt64Array.usizeImpl]

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

          Equations
          Instances For

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

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

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

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

              The element at index i.

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

                For internal use only.

                Equations
                Instances For
                  @[never_extract, extern c inline "#1;\n((uint64_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.

                  Equations
                  Instances For
                    @[never_extract, inline]

                    For internal use only.

                    Equations
                    Instances For
                      @[never_extract, implemented_by ScalarArray.UInt64Array.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.

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

                        Equations
                        Instances For
                          @[inline]

                          For internal use only.

                          Equations
                          Instances For
                            @[never_extract, implemented_by ScalarArray.UInt64Array.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.

                            Equations
                            Instances For
                              @[never_extract, implemented_by ScalarArray.UInt64Array.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.

                              Equations
                              Instances For
                                def ScalarArray.UInt64Array.casesMk {motive : UInt64Array → Sort u} (mk : (a : Array UInt64) → motive (mk a)) (a : UInt64Array) :
                                motive a

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

                                Equations
                                Instances For
                                  @[implemented_by _private.ScalarArray.UInt64.Basic.0.ScalarArray.UInt64Array.emptyWithCapacityImpl]

                                  An empty array with room for capacity elements before reallocating.

                                  Equations
                                  Instances For
                                    @[implemented_by ScalarArray.UInt64Array.usetImpl]
                                    def ScalarArray.UInt64Array.uset (a : UInt64Array) (i : USize) (v : UInt64) (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.

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

                                      For internal use only.

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

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

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

                                          For internal use only.

                                          Equations
                                          Instances For
                                            @[inline]

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

                                            Equations
                                            Instances For
                                              @[inline]

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

                                              Equations
                                              Instances For
                                                @[inline]

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

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

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

                                                    For internal use only.

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For
                                                      @[implemented_by ScalarArray.UInt64Array.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.

                                                      Equations
                                                      Instances For
                                                        @[implemented_by _private.ScalarArray.UInt64.Basic.0.ScalarArray.UInt64Array.appendImpl]

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

                                                        Equations
                                                        Instances For
                                                          @[implemented_by _private.ScalarArray.UInt64.Basic.0.ScalarArray.UInt64Array.copySliceImpl]
                                                          def ScalarArray.UInt64Array.copySlice (src : UInt64Array) (srcOff : Nat) (dest : UInt64Array) (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.

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