Documentation

Complexity.Algorithms.WordRAM.RadixSort.Scan

Native stable digit-selection scan #

The scan appends a stable digit-selected subsequence to a disjoint destination array. Both orders of the two disjoint blocks are allowed, so consecutive radix passes can swap pointers. All loads, address calculations, stores and loop control are native instructions.

Main definitions #

Main results #

@[reducible, inline]

Array length.

Instances For
    @[reducible, inline]

    Source pointer; the sorter returns the final sorted pointer here.

    Instances For
      @[reducible, inline]

      Scratch pointer.

      Instances For
        @[reducible, inline]

        Current bit index.

        Instances For
          @[reducible, inline]

          Digit selected by the current scan.

          Instances For
            @[reducible, inline]

            Constant one.

            Instances For
              @[reducible, inline]

              Constant two.

              Instances For
                @[reducible, inline]

                Input cursor.

                Instances For
                  @[reducible, inline]

                  Output cursor.

                  Instances For
                    @[reducible, inline]

                    Address temporary.

                    Instances For
                      @[reducible, inline]

                      Loaded key.

                      Instances For
                        @[reducible, inline]

                        Current key digit.

                        Instances For
                          @[reducible, inline]

                          Number of key bits, supplied by the caller.

                          Instances For
                            @[reducible, inline]

                            Temporary used to swap the two pointers.

                            Instances For

                              One stable-selection iteration, with every address and counter operation charged.

                              Instances For

                                Reset the input cursor, then perform one stable-selection scan.

                                Instances For
                                  theorem Cslib.Algorithms.WordRAM.RadixSort.Scan.exec {w s d b t : ℕ} (xs acc : List ℕ) (x : WordRAM.Data 16) (hn : x.regs len = xs.length) (hs : x.regs src = s) (hd : x.regs dst = d) (hb : x.regs bit = b) (ht : x.regs tag = t) (ho : x.regs one = 1) (h2 : x.regs two = 2) (hout : x.regs out = acc.length) (hsrc : WordRAM.Block.HoldsList s xs x.mem) (hacc : WordRAM.Block.HoldsList d acc x.mem) (hwords : ∀ v ∈ xs, WordRAM.Fits w v) (hcap : (acc ++ select b t xs).length ≤ xs.length) (hdisj : s + xs.length ≤ d ∨ d + xs.length ≤ s) (hsfit : WordRAM.Fits w (s + xs.length)) (hdfit : WordRAM.Fits w (d + xs.length)) :
                                  ∃ (y : WordRAM.Data 16), WordRAM.ExecWithin w code x y (11 * xs.length + 3) ∧ WordRAM.Block.HoldsList d (acc ++ select b t xs) y.mem ∧ WordRAM.Block.HoldsList s xs y.mem ∧ y.regs out = (acc ++ select b t xs).length ∧ WordRAM.Modifies { base := d, length := xs.length }.footprint x.mem y.mem

                                  Append a stable digit-selected subsequence in 11n+3 instructions. The destination has capacity n; source and destination blocks are disjoint, in either order. The caller's existing destination prefix is retained. Only destination cells may change.