Documentation

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

@[reducible, inline]

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

@[reducible, inline]

Scratch pointer.

@[reducible, inline]

Current bit index.

@[reducible, inline]

Digit selected by the current scan.

@[reducible, inline]

Constant one.

@[reducible, inline]

Constant two.

@[reducible, inline]

Input cursor.

@[reducible, inline]

Output cursor.

@[reducible, inline]

Address temporary.

@[reducible, inline]

Loaded key.

@[reducible, inline]

Current key digit.

@[reducible, inline]

Number of key bits, supplied by the caller.

@[reducible, inline]

Temporary used to swap the two pointers.

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

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

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.