Burrows–Wheeler Inversion on the Word-RAM #
Linear-time implementation of Algorithm D of [BW94] (Sections 2 and 4.2) on the
standard-basis Word-RAM (Basis.standard) for words over a bounded integer alphabet [0, σ):
buildTablesCodeclearsσbuckets atcBaseviazeroFill, scans the last columnLonce to populate both the rank arrayP[0..|L|)(rankTable L) atpBaseand per-symbol frequencies incBase, and runs an exclusive prefix-sum scan over[0, σ)so thatC[b] = L.countP (· < b), in11 * σ + 11 * |L| + 13machine instructions.lfDecodeCodeexecutes up to|L|table-driven LF stepsr ↦ P[r] + C[L[r]]from rowI, writing decoded symbols backwards into an output buffer so that halting returnsinverseBwt (L, I)as a length-prefixed array without a post-copy pass, in14 * |L| + 9machine instructions.decodeCode/decodeProgramunpacks an encoded inputinp = ⟨L, I, σ⟩([I, σ] ++ L), placesC,P, and the output buffer in disjoint regions after the input, and returnsinverseBwt (L, I)in at most25 * |L| + 11 * σ + 34instructions at any word widthwwithFits w (3 * |L| + σ + 4)(andInputFits w inp.encodeindecodeProgram_computesListInTimeto bound an arbitrary encoded starting rowI). Onbwt u(with∀ c ∈ u, c < σ),decodeProgram_bwtdischargesInputFitsautomatically frombwtIndex u ≤ |u|and recoversuinO(|u| + σ)instructions.
Main definitions #
Cslib.Algorithms.WordRAM.BurrowsWheeler.Input: integer-alphabet decoder input⟨L, I, σ⟩.Cslib.Algorithms.WordRAM.BurrowsWheeler.buildTablesCode:O(|L| + σ)CandPtable builder.Cslib.Algorithms.WordRAM.BurrowsWheeler.lfDecodeCode:O(|L|)table-driven LF-step decoder.Cslib.Algorithms.WordRAM.BurrowsWheeler.decodeCode,decodeProgram: end-to-end BWT inversion.
Main results #
Cslib.Algorithms.WordRAM.BurrowsWheeler.buildTablesCode_exec: buildsCandrankTable Lwithin11 * σ + 11 * |L| + 13instructions.Cslib.Algorithms.WordRAM.BurrowsWheeler.lfDecodeCode_exec: decodesinverseBwt (L, I)within14 * |L| + 9instructions.Cslib.Algorithms.WordRAM.BurrowsWheeler.decodeCode_exec,Cslib.Algorithms.WordRAM.BurrowsWheeler.decodeProgram_computesListInTime: end-to-endO(|L| + σ)Word-RAM BWT inversion.Cslib.Algorithms.WordRAM.BurrowsWheeler.decodeProgram_bwt: recoversufrombwt uwithin25 * |u| + 11 * σ + 34instructions whenever∀ c ∈ u, c < σandFits w (3 * |u| + σ + 4).
References #
Input encoding and pure count identities #
Every symbol of inp.last lies in [0, inp.alphabetSize).
Word-array encoding [I, σ] ++ L: Data.init places |L| + 2 at address 0, I at 1,
σ at 2, and L[0..|L|) at 3..|L|+2.
Base address of input last column L.
Length n = |L|.
Alphabet upper bound σ.
Starting / current row index r.
Base address of cumulative count table C[0..σ).
Base address of rank table P[0..n).
Base address of output buffer [buf..buf+n].
Output list header address returned at halt.
Word-RAM structured code #
Unpack Input.encode ([I, σ] ++ L at Data.init), allocate C, P, and buf after the
input, build the tables, and run LF decoding.
Flat Word-RAM program computing inverseBwt (inp.last, inp.index) from inp.encode.
Correctness and running time of buildTablesCode #
buildTablesCode builds C[0..sigma) at cBase and rankTable L at pBase within
11 * sigma + 11 * |L| + 13 instructions, preserving all other memory cells and the parameter
registers 0..6.
Correctness and running time of lfDecodeCode #
lfDecodeCode computes inverseBwt (L, row) as a length-prefixed array inside [buf..buf+|L|]
within 14 * |L| + 9 instructions.
End-to-end Word-RAM BWT decoder #
decodeCode inverts inp = ⟨L, I, σ⟩ from Data.init inp.encode within
25 * |L| + 11 * σ + 33 instructions at any fitting width Fits w (3 * |L| + σ + 4).
decodeProgram computes inverseBwt (inp.last, inp.index) in 25 * |L| + 11 * σ + 34
instructions at every fitting width with inp.Valid, Fits w (3 * |L| + σ + 4), and
InputFits w inp.encode (the ComputesListInTime input-fit hypothesis, which bounds an arbitrary
encoded starting row I).
On bwt u over an integer alphabet < σ, decodeProgram recovers u within
25 * |u| + 11 * σ + 34 instructions at any word width w with Fits w (3 * |u| + σ + 4).