Go index/suffixarray: logarithmic substring search over in-memory data
Answer: Package suffixarray implements substring search in logarithmic time using an in-memory suffix array.
Building the index
New builds an Index over data. Creation time is O(N), with N equal to len(data).
Bytes returns the data over which the index was created. It must not be modified.
Write writes the index x to w. Read reads the index from r into x; x must not be nil.
Looking up substrings
Lookup returns indices where s occurs. When n is -1, Lookup returns all indices where s occurs. Lookup can also return a list of at most n indices.
The result is nil if s is empty, if s is not found, or if n == 0.
A Lookup costs O(log(N)*len(s) + len(result)), and N is the indexed data size.
FindAllIndex returns a sorted list of non-overlapping matches of the regular expression r. If n < 0, all matches are returned in successive order.
See also
Claims
- id: C1 claim: Building the index takes time linear in the data length. source: S1 evidence: "Index creation time is O(N) for N = len(data)."
- id: C2 claim: The underlying data slice must not be modified. source: S1 evidence: "It must not be modified."
- id: C3 claim: The package comment describes logarithmic-time substring search. source: S2 evidence: "Package suffixarray implements substring search in logarithmic time using"
Sources
- [S1] index/suffixarray. The Go Authors. https://pkg.go.dev/index/suffixarray . License: BSD-3-Clause. Accessed 2026-11-26.
- [S2] suffixarray.go (source). The Go Authors. https://go.dev/src/index/suffixarray/suffixarray.go . License: BSD-3-Clause. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, index/suffixarray; The Go Authors, suffixarray.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, index/suffixarray; The Go Authors, suffixarray.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go index/suffixarray: logarithmic substring search over in-memory data." iinventedlight Library, iil:note:mcex8dhv, version of 2026-11-26. https://iinventedlight.com/library/notes/go-index-suffixarray/. License: CC-BY-4.0.
@misc{iil_note_mcex8dhv,
author = {{iinventedlight}},
title = {{Go index/suffixarray: logarithmic substring search over in-memory data}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/go-index-suffixarray/},
note = {Permanent ID iil:note:mcex8dhv. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-index-suffixarray.schema.json (schema; CC-BY-4.0)
- go-index-suffixarray.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-index-suffixarray.md.