Table-driven inversion of the Burrows–Wheeler transform #
[BW94], Section 4.2, inverts the transform with two tables computed from the last
column L: C[c], the number of symbols of L smaller than c, and the rank array P, where
P[i] counts the occurrences of L[i] in L[0..i-1]. The LF-mapping is then the lookup
T i = P[i] + C[L[i]], and the word is decoded by |L| such lookups.
For bounded integer alphabets < σ, CslibFrontier.Algorithms.WordRAM.BurrowsWheeler builds C
and P in O(|L| + σ) Word-RAM instructions and runs the |L| LF-step lookups in O(|L|)
instructions.
Main definitions #
rankTableFrom,rankTable: the rank arrayPof [BW94], Section 4.2.lfDecodeTable L C P k r acc:ktable-driven LF stepsr ↦ P[r] + C[L[r]]from rowr.inverseBwtTable L I C P:|L|table-driven LF steps from rowI.
Main results #
getElem?_rankTable,getElem_rankTable:P[i] = (L.take i).count L[i].lfDecodeTable_eq_lfDecode: whenCagrees withL.countP (· < c)on symbols ofL,lfDecodeTable L C (rankTable L)computeslfDecode L.inverseBwtTable_eq_inverseBwt,inverseBwtTable_bwt: table-driven decoding computesinverseBwt (L, I)and recoverswfrombwt w.
References #
The rank table #
rankTableFrom cnt L lists, for each position i, cnt L[i] plus the number of earlier
occurrences of L[i]. It is one left-to-right pass with a running count per symbol.
The rank array P of [BW94], Section 4.2: P[i] is the number of occurrences
of L[i] before position i (Batteries' L.countBefore L[i] i).
Table-driven LF decoding #
k LF steps from row r with the tables C and P, prepending the symbols read to acc.
Each step reads L[r] and P[r] and moves to P[r] + C[L[r]] ([BW94],
Section 4.2). It stops early out of range.
With P = rankTable L and C matching L.countP (· < c) on every symbol in L,
lfDecodeTable computes lfDecode.
Table-driven decoding of bwt w recovers w.