← All notes

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

Sources

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

Permanent ID: iil:note:mcex8dhv

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.},
}

Markdown

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.

All artifact files (JSON index)

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.