Manuscript Offprint
arXiv:2609.06596Tunnelling with a reference
Abstract
We show how to modify Baier's tunnelling for the case in which we have a non-repetitive and relatively short reference for a highly repetitive and much longer text. Given a pattern that mostly matches only one substring of the reference, we can use fairly small auxiliary data structures to speed up backward searching with an r-index for the whole text.
1 Introduction
Perhaps the most surprising thing about Gagie, Navarro and Prezza's [9] r-index was that it supported locating in time, whereas the fastest locating time with a standard FM-index [7] or compressed suffix array (CSA) [10, 13] is . In other words, we can achieve not only better compression when working with highly repetitive datasets, but also better query times. Their result was quickly followed by Nishimoto and Tabei's [11] proof that r-indexes can use table lookup instead of bitvectors, resulting in better locality and even faster queries (see also, e.g., [14]). Balázs et al. [3] introduced tag arrays (see also [6, 12]) to allow r-indexes to quickly find all the columns in a multiple alignment where occurrences of a pattern start, rather than listing all the starting positions of those occurrences. Finally, Depuydt et al. [5] introduced suffixent sets (see also, e.g., [4]) to replace backward stepping in the r-index by sequential scanning in the text. None of these ideas make sense for non-repetitive texts.
Suffixent sets are just the latest way to gain an advantage by switching back and forth between the order of characters as they appear in a text, and the order of the suffixes that follow them. CSAs use this switching more than textbook FM-indexes, which use it only during locating to find characters' text positions from their positions in the Burrows-Wheeler Transform (BWT), but practical implementations of FM-indexes often switch earlier once they have found there are at most a few occurrences of a pattern. As an illustration of this idea, we include the following lemma. It is not meant to be competitive with the state of the art and could easily be improved with more sophisticated data structures, such as Ferragina and Venturini's [8] data structure for supporting fast access to a compressed string, but we hope it gives the flavour of how switching between text order and BWT order can be advantageous.
Lemma 1. Given a text over an alphabet of size and a constant , we can store in bits such that, when given a pattern packed into words with a suffix that occurs only once in , we can
-
find the length of the longest suffix of that occurs in (which may be ),
-
find the position in of the unique occurrence of that suffix of ,
-
find the lexicographic rank of the suffix of starting with that occurrence among all the suffixes of ,
all in time. We need not be given .
Proof. We store an FM-index for with -time access to the suffix array (SA) and inverse suffix array (ISA) of , and a copy of packed into words. This takes a total of bits.
When given , we backward search for it until the BWT interval shrinks to a single character, after backward steps and time. We then perform an -time SA query to find the position in of the unique occurrence of . We compare to from right to left in blocks of characters until we have determined that they are equal or found the rightmost character where they differ, in time. This tells us the length of the longest suffix of that occurs in and the position in of the unique occurrence of that suffix of . We use an -time ISA query to find the lexicographic rank of the suffix of starting with that occurrence among all the suffixes of .
This takes a total of time and, since and , that is .
Ayad et al. [1] already applied a more sophisticated version of Lemma 1 in their U-index for highly repetitive texts, but in this paper we will consider how Lemma 1 can be combined with Baier's [2] idea of tunnelling (modified to use a reference and to allow substrings to leave tunnels in the middle) to give a new result for indexing highly repetitive texts.
For each character in R we consider the interval in the BWT of T such that, for each character BWT[i] in the interval,
- if is the length of the longest common prefix of and then the length of the longest common prefix of and is strictly less than for every ,
• for a length we will discuss later.
Such an interval for a character can be empty but, by the first constraint, the n intervals for the characters in R are disjoint. We call these intervals tunnel entrances.
We store two sparse N-bit bit vectors, with the 1s in the first marking the starting positions of tunnel entrances, and the 1s in the other marking the ending positions of the tunnel entrances. These take bits and let us check in time whether the BWT interval for a suffix of a pattern is contained within a tunnel entrance. We also store the value j with the tunnel entrance for , which will avoid the need for SA queries.
For , let be the probability that a character BWT[i] in the tunnel entrance for has
•
taken over all the characters in all the tunnel entrances. (Notice that a character in the tunnel entrance for immediately precedes an occurrence of but need not be equal to itself.) Assuming is not itself repetitive, should be close to 1 and thus close to 0 for . For the rest of this paper we consider to be some such value.
Let be the total length of the tunnel entrances. We store a sparse -bit bitvector with 1s marking each character BWT[i] in a tunnel entrance for a character of that does not have
•
Since exactly a fraction of the bitvector consists of 1s, by the definition of , this bitvector takes bits.
Finally, for each character in we store the endpoints of the interval of the BWT containing the characters characters to the left in of the BWT characters marked by 0s in the part of the -bit bitvector covering the tunnel entrance for . We call these intervals tunnel exits, and the tunnel exit for is a subinterval of the tunnel entrance for . Storing the endpoints of all the tunnel exits takes a total of bits, and will avoid the need for ISA queries.
Considering all these data structures, we use bits. (This is on top of the bits we need for an r-index for that our data structures will speed up, where is the number of runs in the BWT of .) In the next section we explain how we use the tunnel entrances and exits to speed up pattern matching.
3 Pattern matching
Given a pattern packed into words, we perform a standard backward search for with the r-index for , except that after finding the BWT interval for each suffix of we check the sparse -bit bitvectors in time to see if that interval is contained in the tunnel entrance for some character in . If so and , we compare to in time. If they are equal then we use the rank queries on the -bit bitvector to find the subinterval of the tunnel exit for that is the BWT interval for in time. Since the tunnel exit for is a subinterval of the tunnel entrance for , we can continue like this until we find a mismatch between and . At that point we fall back on backward stepping with the r-index (now without checking for tunnel entrances). After some calculation, this gives us the following theorem.
Theorem 2. Suppose we are given a reference for a highly repetitive text over an alphabet of size , with , and an integer with . Then we can store
• an r-index for T in bits, where r is the number of runs in the BWT of T,
- auxiliary data structures in a total of bits, where is a probability depending on , and but usually close to 0,
such that we can speed up pattern matching with that r-index when a long substring of the pattern matches a single long substring of the reference. Specifically, given a pattern packed into words whose longest and shortest suffixes occurring exactly once each in are and , respectively, we can
-
find the length of the longest suffix of that occurs in (which may be ),
-
find the BWT interval for that suffix of ,
in total time
With more care it is possible to use the auxiliary data structures to speed up the search even when the suffix of we have processed has no matches in , as long as a sufficiently long prefix of that suffix has a single match in . We leave the details of that more sophisticated technique for the full version of this paper.
References
[1] Lorraine A. K. Ayad, Gabriele Fici, Ragnar Groot Koerkamp, Grigorios Loukides, Rob Patro, Giulio Ermanno Pibiri, and Solon P. Pissis. U-index: A universal indexing framework for matching long patterns. In Proc. 23rd Symposium on Experimental Algorithms (SEA), 2025.
[2] Uwe Baier. On undetected redundancy in the Burrows-Wheeler Transform. In Proc. 29th Symposium on Combinatorial Pattern Matching (CPM), 2018.
[3] Andrej Balázs, Travis Gagie, Adrián Goga, Simon Heumos, Gonzalo Navarro, Alessia Petescia, and Jouni Sirén. Wheeler maps. In Proc. 16th Latin American Symposium on Theoretical Informatics (LATIN), 2024.
[4] Ruben Becker, Davide Cenzato, Travis Gagie, Ragnar Groot Koerkamp, Sung-Hwan Kim, Giovanni Manzini, and Nicola Prezza. Compressing suffix trees by path decompositions. In Proc. 53rd International Colloquium on Automata, Languages, and Programming (ICALP), 2026.
[5] Lore Depuydt, Travis Gagie, Ben Langmead, Giovanni Manzini, and Nicola Prezza. Suffixient sets. arXiv:2312.01359, 2023.
[6] Parsa Eskandar, Benedict Paten, and Jouni Sirén. Lossless pangenome indexing using tag arrays. Algorithms for Molecular Biology, 2026.
[7] Paolo Ferragina and Giovanni Manzini. Indexing compressed text. Journal of the ACM, 2005.
[8] Paolo Ferragina and Rossano Venturini. A simple storage scheme for strings achieving entropy bounds. Theoretical Computer Science, 2007.
[9] Travis Gagie, Gonzalo Navarro, and Nicola Prezza. Fully functional suffix trees and optimal text searching in BWT-runs bounded space. Journal of the ACM, 2020.
[10] Roberto Grossi and Jeffrey Scott Vitter. Compressed suffix arrays and suffix trees with applications to text indexing and string matching. SIAM Journal on Computing, 2005.
[11] Takaaki Nishimoto and Yasuo Tabei. Optimal-time queries on BWT-runs compressed indexes. In Proc. 48th International Colloquium on Automata, Languages, and Programming (ICALP), 2021.
[12] Jannik Olbrich and Enno Ohlebusch. The TAG array of a multiple sequence alignment. In Proc. 37th Symposium on Combinatorial Pattern Matching (CPM), 2026.
[13] Kunihiko Sadakane. New text indexing functionalities of the compressed suffix arrays. Journal of Algorithms, 2003.
[14] Mohsen Zakeri, Nathaniel K Brown, Travis Gagie, and Ben Langmead. Movi 2: fast and space-efficient queries on pangenomes. Bioinformatics, 2026.