Documentation
¶
Overview ¶
Package trie provides a prefix tree implementation.
Add, Has and Delete operations are linear in query length, regardless of the size of the trie. All operations are non-recursive except for marshaling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
A Trie is a prefix tree that supports lookups. A zero value trie is invalid; use New to create a new instance.
func (*Trie) Add ¶
Add inserts b and its prefixes to the trie. If b was already added, the object is unchanged.
func (*Trie) Delete ¶
Delete removes prefix b from the trie. All sequences that have b as their prefix are removed. All other sequences are unchanged. Returns the result of calling Has(b) before deleting.
func (*Trie) ForEach ¶ added in v0.1.16
ForEach calls f for each final sequence (leaf) in the trie. A final sequence is a sequence that is not a prefix of a longer sequence. f should return whether or not the iteration should continue. f's input slice may be overwritten by subsequent iterations.
func (*Trie) Has ¶
Has checks whether b was added to the trie. b could have been added by being a prefix of a longer input.
func (*Trie) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Trie) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.