arXiv:2609.06596cs.DSSep 2026

Manuscript Offprint

arXiv:2609.06596

Tunnelling with a reference

Travis Gagie

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 O(log⁡log⁡n)O(\log \log n) time, whereas the fastest locating time with a standard FM-index [7] or compressed suffix array (CSA) [10, 13] is O(log⁡σϵn)O(\log_{\sigma}^{\epsilon} n). 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 T[1..n]T[1..n] over an alphabet of size σ≤n\sigma \leq n and a constant ϵ>0\epsilon > 0, we can store TT in O(nlog⁡σ)O(n \log \sigma) bits such that, when given a pattern P[1..m]P[1..m] packed into O(mlog⁡σlog⁡n)O\left(\frac{m \log \sigma}{\log n}\right) words with a suffix P[m−s+1..m]P[m-s+1..m] that occurs only once in TT, we can

  • find the length of the longest suffix of PP that occurs in TT (which may be mm),

  • find the position in TT of the unique occurrence of that suffix of PP,

  • find the lexicographic rank of the suffix of TT starting with that occurrence among all the suffixes of TT,

all in O(slog⁡σ+(m−s)log⁡σlog⁡n+log⁡1+ϵn)O\left(s\log\sigma+\frac{(m-s)\log\sigma}{\log n}+\log^{1+\epsilon}n\right) time. We need not be given ss.

Proof. We store an FM-index for TT with O(log⁡1+ϵn)O(\log^{1+\epsilon}n)-time access to the suffix array (SA) and inverse suffix array (ISA) of TT, and a copy of TT packed into O(nlog⁡σlog⁡n)O\left(\frac{n\log\sigma}{\log n}\right) words. This takes a total of O(nlog⁡σ)O(n\log\sigma) bits.

When given PP, we backward search for it until the BWT interval shrinks to a single character, after b≤sb \leq s backward steps and O(blog⁡σ)O(b\log\sigma) time. We then perform an O(log⁡1+ϵn)O(\log^{1+\epsilon}n)-time SA query to find the position ii in TT of the unique occurrence of P[m−b+1..m]P[m-b+1..m]. We compare T[i−m+b..i−1]T[i-m+b..i-1] to P[1..m−b]P[1..m-b] from right to left in blocks of O(log⁡σlog⁡n)O\left(\frac{\log\sigma}{\log n}\right) characters until we have determined that they are equal or found the rightmost character where they differ, in O((m−b)log⁡σlog⁡n)O\left(\frac{(m-b)\log\sigma}{\log n}\right) time. This tells us the length of the longest suffix of PP that occurs in TT and the position in TT of the unique occurrence of that suffix of PP. We use an O(log⁡1+ϵn)O(\log^{1+\epsilon}n)-time ISA query to find the lexicographic rank of the suffix of TT starting with that occurrence among all the suffixes of TT.

This takes a total of O(blog⁡σ+(m−b)log⁡σlog⁡n+log⁡1+ϵn)O\left(b\log\sigma+\frac{(m-b)\log\sigma}{\log n}+\log^{1+\epsilon}n\right) time and, since b≤sb\leq s and σ≤n\sigma\leq n, that is O(slog⁡σ+(m−s)log⁡σlog⁡n+log⁡1+ϵn)O\left(s\log\sigma+\frac{(m-s)\log\sigma}{\log n}+\log^{1+\epsilon}n\right).

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.