diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/go/index%2Fsuffixarray%2Findex.html | |
new repository
Diffstat (limited to 'devdocs/go/index%2Fsuffixarray%2Findex.html')
| -rw-r--r-- | devdocs/go/index%2Fsuffixarray%2Findex.html | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/devdocs/go/index%2Fsuffixarray%2Findex.html b/devdocs/go/index%2Fsuffixarray%2Findex.html new file mode 100644 index 00000000..39fab1b8 --- /dev/null +++ b/devdocs/go/index%2Fsuffixarray%2Findex.html @@ -0,0 +1,50 @@ +<h1> Package suffixarray </h1> <ul id="short-nav"> +<li><code>import "index/suffixarray"</code></li> +<li><a href="#pkg-overview" class="overviewLink">Overview</a></li> +<li><a href="#pkg-index" class="indexLink">Index</a></li> +<li><a href="#pkg-examples" class="examplesLink">Examples</a></li> +</ul> <h2 id="pkg-overview">Overview </h2> <p>Package suffixarray implements substring search in logarithmic time using an in-memory suffix array. </p> +<p>Example use: </p> +<pre data-language="go">// create index for some data +index := suffixarray.New(data) + +// lookup byte slice s +offsets1 := index.Lookup(s, -1) // the list of all indices where s occurs in data +offsets2 := index.Lookup(s, 3) // the list of at most 3 indices where s occurs in data +</pre> <h2 id="pkg-index">Index </h2> <ul id="manual-nav"> +<li><a href="#Index">type Index</a></li> +<li> <a href="#New">func New(data []byte) *Index</a> +</li> +<li> <a href="#Index.Bytes">func (x *Index) Bytes() []byte</a> +</li> +<li> <a href="#Index.FindAllIndex">func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int)</a> +</li> +<li> <a href="#Index.Lookup">func (x *Index) Lookup(s []byte, n int) (result []int)</a> +</li> +<li> <a href="#Index.Read">func (x *Index) Read(r io.Reader) error</a> +</li> +<li> <a href="#Index.Write">func (x *Index) Write(w io.Writer) error</a> +</li> +</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_Index_Lookup">Index.Lookup</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>sais.go</span> <span>sais2.go</span> <span>suffixarray.go</span> </p> <h2 id="Index">type <span>Index</span> </h2> <p>Index implements a suffix array for fast substring search. </p> +<pre data-language="go">type Index struct { + // contains filtered or unexported fields +} +</pre> <h3 id="New">func <span>New</span> </h3> <pre data-language="go">func New(data []byte) *Index</pre> <p>New creates a new <a href="#Index">Index</a> for data. <a href="#Index">Index</a> creation time is O(N) for N = len(data). </p> +<h3 id="Index.Bytes">func (*Index) <span>Bytes</span> </h3> <pre data-language="go">func (x *Index) Bytes() []byte</pre> <p>Bytes returns the data over which the index was created. It must not be modified. </p> +<h3 id="Index.FindAllIndex">func (*Index) <span>FindAllIndex</span> </h3> <pre data-language="go">func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int)</pre> <p>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. </p> +<h3 id="Index.Lookup">func (*Index) <span>Lookup</span> </h3> <pre data-language="go">func (x *Index) Lookup(s []byte, n int) (result []int)</pre> <p>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. </p> <h4 id="example_Index_Lookup"> <span class="text">Example</span> +</h4> <p>Code:</p> <pre class="code" data-language="go">index := suffixarray.New([]byte("banana")) +offsets := index.Lookup([]byte("ana"), -1) +for _, off := range offsets { + fmt.Println(off) +} + +</pre> <p>Output:</p> <pre class="output" data-language="go">1 +3 +</pre> <h3 id="Index.Read">func (*Index) <span>Read</span> </h3> <pre data-language="go">func (x *Index) Read(r io.Reader) error</pre> <p>Read reads the index from r into x; x must not be nil. </p> +<h3 id="Index.Write">func (*Index) <span>Write</span> </h3> <pre data-language="go">func (x *Index) Write(w io.Writer) error</pre> <p>Write writes the index x to w. </p><div class="_attribution"> + <p class="_attribution-p"> + © Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br> + <a href="http://golang.org/pkg/index/suffixarray/" class="_attribution-link">http://golang.org/pkg/index/suffixarray/</a> + </p> +</div> |
