arXiv:2609.40299cs.DSSep 2026

Manuscript Offprint

arXiv:2609.40299

Mixing FM-indexes and CSAs: backward search over an order-1 rank encoding

Travis Gagie

Abstract

FM-indexes and compressed suffix arrays (CSAs) are often treated as interchangeable, but they behave differently as the alphabet grows. An FM-index step costs about one cache miss per level of a wavelet tree, so it gets slower with the alphabet size. A CSA step is a binary search whose range shrinks as characters get rarer. We describe a simple hybrid. Each character of the text is replaced by the rank of its frequency among the characters that follow the previous character. We backward-search on this encoding, which is over a small, skewed alphabet, and recover the one piece of information the encoding loses (the first character of the pattern) with a single CSA-like step on an array we call ΨE\Psi_E. Counting is exact, and locating works with standard suffix-array sampling. A prototype on synthetic repetitive data shows that the hybrid is the fastest of the indexes we tried at intermediate alphabet sizes with 1% noise, but even its compact version is 1.7 to 3.9 times larger than a compressed run-length CSA or FM-index of the original text, because the encoding and ΨE\Psi_E together have more runs than the original Burrows–Wheeler transform. Whether that changes on real data, such as parses and minimizer digests, is the main open question.

1 Introduction

Indexes for highly repetitive text collections, such as pangenomes, are usually built for small alphabets: DNA has four characters. Increasingly, though, we want to index repetitive sequences over large alphabets. In two-level indexing we index the parse of a text, whose alphabet is the dictionary of distinct phrases [3, 14]. Minimizer digests of pangenomes treat each minimizer as a meta-character [1]. Collections of versioned documents can be viewed as sequences of words [6]. These sequences are still repetitive, so their Burrows–Wheeler transforms (BWTs) still have relatively few runs, but the alphabets have thousands or millions of symbols.

For such data, the choice between the two classic families of compressed indexes matters. The FM-index [8] represents the BWT with a wavelet tree, and one backward-search step costs one rank query per level of the tree: about lg⁡σ\lg \sigma levels for an alphabet of size σ\sigma, or about H0H_0 levels with a Huffman-shaped tree. Each level is a separate bitvector, so each level can cost a cache miss. A compressed suffix array (CSA) [13] instead stores the permutation Ψ\Psi, and one step is a binary search in the part of Ψ\Psi belonging to one character, whose length is that character's frequency (or, in a run-length compressed CSA, its number of runs [3]). For large alphabets those parts are short, so CSAs tend to win; for small alphabets FM-indexes tend to win.

The idea, informally. In most real sequences, the previous character tells us a lot about the next one. Instead of storing each character, we store how surprising it is: its rank by frequency among the characters that follow the previous character in the text. In English, after “q” comes “u” almost always, so “u” after “q” becomes a 1. The encoded text E is then mostly small numbers (on our test data, mostly 1s), so backward search on E can use a very shallow wavelet tree. We can encode a pattern P the same way, using the text’s rankings, and search for it in E. The catch is that the encoding of P only makes sense given P’s first character: the string of ranks “1, 1, 1” means “ANA” after a B but “BAN” after a _. So after the search, we must keep only the encoded suffixes that are preceded in the text by P[0]. We do that with one lookup in an array ΨE\Psi_E of the (unencoded) characters that precede the encoded suffixes, stored the way a CSA stores Ψ\Psi. The result is an FM-index for all but one step of the search, and a CSA for the last one, which is the only step that has to deal with the large alphabet.

What we found. The hybrid is correct and simple to implement. On synthetic repetitive data it has the following properties:

  • Its query time barely depends on the alphabet size, because the Huffman-shaped wavelet tree over the encoding has depth about 2 whatever the alphabet.

  • At intermediate alphabet sizes (10 to 10,000) with 1% noise, it is the fastest of the indexes we tried, by 1.1 to 1.8 times (the smallest margin is within measurement noise).

  • It is never the smallest. The encoding and ΨE\Psi_{E} together have 1.6 to 4.1 times as many runs as the BWT of the text, so even the compact hybrid is 1.7 to 3.9 times larger than a compressed run-length CSA of the text, and no faster than it.

So on this data the hybrid buys speed with space, and its compact version is dominated. The question that decides whether it is useful is how many runs the encoding and ΨE\Psi_{E} have on real parses and digests.

Organization. Section 2 reviews FM-indexes, CSAs and their run-length versions on a small example, with attention to memory locality. Section 3 describes the hybrid on the same example, proves that counting is exact, and sketches locating. Section 4 discusses related work, Section 5 our implementation, Section 6 experiments, and Section 7 open questions, including what the hybrid means for move structures.