var maxData32 … const realMaxData32 … type Index … type ints … func (a *ints) len() int { … } func (a *ints) get(i int) int64 { … } func (a *ints) set(i int, v int64) { … } func (a *ints) slice(i, j int) ints { … } // New creates a new [Index] for data. // [Index] creation time is O(N) for N = len(data). func New(data []byte) *Index { … } // writeInt writes an int x to w using buf to buffer the write. func writeInt(w io.Writer, buf []byte, x int) error { … } // readInt reads an int x from r using buf to buffer the read and returns x. func readInt(r io.Reader, buf []byte) (int64, error) { … } // writeSlice writes data[:n] to w and returns n. // It uses buf to buffer the write. func writeSlice(w io.Writer, buf []byte, data ints) (n int, err error) { … } var errTooBig … // readSlice reads data[:n] from r and returns n. // It uses buf to buffer the read. func readSlice(r io.Reader, buf []byte, data ints) (n int, err error) { … } const bufSize … // Read reads the index from r into x; x must not be nil. func (x *Index) Read(r io.Reader) error { … } // Write writes the index x to w. func (x *Index) Write(w io.Writer) error { … } // Bytes returns the data over which the index was created. // It must not be modified. func (x *Index) Bytes() []byte { … } func (x *Index) at(i int) []byte { … } // lookupAll returns a slice into the matching region of the index. // The runtime is O(log(N)*len(s)). func (x *Index) lookupAll(s []byte) ints { … } // Lookup returns an unsorted list of at most n indices where the byte string s // occurs in the indexed data. If n < 0, all occurrences are returned. // The result is nil if s is empty, s is not found, or n == 0. // Lookup time is O(log(N)*len(s) + len(result)) where N is the // size of the indexed data. func (x *Index) Lookup(s []byte, n int) (result []int) { … } // FindAllIndex returns a sorted list of non-overlapping matches of the // regular expression r, where a match is a pair of indices specifying // the matched slice of x.Bytes(). If n < 0, all matches are returned // in successive order. Otherwise, at most n matches are returned and // they may not be successive. The result is nil if there are no matches, // or if n == 0. func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int) { … }