forked from zyedidia/generic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
244 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<!-- Code generated by gomarkdoc. DO NOT EDIT --> | ||
|
||
# trie | ||
|
||
```go | ||
import "github.com/zyedidia/generic/trie" | ||
``` | ||
|
||
Package trie provides an implementation of a ternary search trie\. | ||
|
||
<details><summary>Example</summary> | ||
<p> | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/zyedidia/generic/trie" | ||
) | ||
|
||
func main() { | ||
tr := trie.New[int]() | ||
tr.Put("foo", 1) | ||
tr.Put("fo", 2) | ||
tr.Put("bar", 3) | ||
|
||
fmt.Println(tr.Contains("f")) | ||
fmt.Println(tr.KeysWithPrefix("")) | ||
fmt.Println(tr.KeysWithPrefix("f")) | ||
} | ||
``` | ||
|
||
#### Output | ||
|
||
``` | ||
false | ||
[bar fo foo] | ||
[fo foo] | ||
``` | ||
|
||
</p> | ||
</details> | ||
|
||
## Index | ||
|
||
- [type Trie](<#type-trie>) | ||
- [func New[V any]() *Trie[V]](<#func-new>) | ||
- [func (t *Trie[V]) Contains(key string) bool](<#func-badrecv-contains>) | ||
- [func (t *Trie[V]) Get(key string) (v V, ok bool)](<#func-badrecv-get>) | ||
- [func (t *Trie[V]) Keys() (queue []string)](<#func-badrecv-keys>) | ||
- [func (t *Trie[V]) KeysWithPrefix(prefix string) (queue []string)](<#func-badrecv-keyswithprefix>) | ||
- [func (t *Trie[V]) LongestPrefix(query string) string](<#func-badrecv-longestprefix>) | ||
- [func (t *Trie[V]) Put(key string, val V)](<#func-badrecv-put>) | ||
- [func (t *Trie[V]) Remove(key string)](<#func-badrecv-remove>) | ||
- [func (t *Trie[V]) Size() int](<#func-badrecv-size>) | ||
|
||
|
||
## type Trie | ||
|
||
A Trie is a data structure that supports common prefix operations\. | ||
|
||
```go | ||
type Trie[V any] struct { | ||
// contains filtered or unexported fields | ||
} | ||
``` | ||
|
||
### func New | ||
|
||
```go | ||
func New[V any]() *Trie[V] | ||
``` | ||
|
||
New returns an empty trie\. | ||
|
||
### func \(\*BADRECV\) Contains | ||
|
||
```go | ||
func (t *Trie[V]) Contains(key string) bool | ||
``` | ||
|
||
Contains returns whether this trie contains 'key'\. | ||
|
||
### func \(\*BADRECV\) Get | ||
|
||
```go | ||
func (t *Trie[V]) Get(key string) (v V, ok bool) | ||
``` | ||
|
||
Get returns the value associated with 'key'\. | ||
|
||
### func \(\*BADRECV\) Keys | ||
|
||
```go | ||
func (t *Trie[V]) Keys() (queue []string) | ||
``` | ||
|
||
Keys returns all keys in the trie\. | ||
|
||
### func \(\*BADRECV\) KeysWithPrefix | ||
|
||
```go | ||
func (t *Trie[V]) KeysWithPrefix(prefix string) (queue []string) | ||
``` | ||
|
||
KeysWithPrefix returns all keys with prefix 'prefix'\. | ||
|
||
### func \(\*BADRECV\) LongestPrefix | ||
|
||
```go | ||
func (t *Trie[V]) LongestPrefix(query string) string | ||
``` | ||
|
||
LongestPrefix returns the key that is the longest prefix of 'query'\. | ||
|
||
### func \(\*BADRECV\) Put | ||
|
||
```go | ||
func (t *Trie[V]) Put(key string, val V) | ||
``` | ||
|
||
Put associates 'val' with 'key'\. | ||
|
||
### func \(\*BADRECV\) Remove | ||
|
||
```go | ||
func (t *Trie[V]) Remove(key string) | ||
``` | ||
|
||
Remove removes the value associated with 'key'\. | ||
|
||
### func \(\*BADRECV\) Size | ||
|
||
```go | ||
func (t *Trie[V]) Size() int | ||
``` | ||
|
||
Size returns the size of the trie\. | ||
|
||
|
||
|
||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>) |
Oops, something went wrong.