trie

package module
v0.0.0-...-945f4df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2014 License: MIT Imports: 2 Imported by: 0

README

Trie

Implements:

  • A trie, use it like a map[string]interface{}.
  • A ternary search tree, like a map[string]interface{} from which you cannot delete.
  • A trieset, use it like a map[string]struct{}.

Performance

This benchmarks shows lookups only (Get):

keys map[string]bool trie.TernaryST trie.Trie
4 7.36 ns/op 24.1 ns/op 28.4 ns/op
8 7.37 ns/op 24.3 ns/op 28.3 ns/op
16 28.6 ns/op 33.4 ns/op 35.0 ns/op
32 24.6 ns/op 33.7 ns/op 35.3 ns/op
64 25.1 ns/op 33.2 ns/op 35.2 ns/op
512 24.4 ns/op 38.5 ns/op 42.0 ns/op
1024 33.9 ns/op 43.5 ns/op 49.5 ns/op
1M 32.1 ns/op 58.5 ns/op 72.2 ns/op

License

MIT, see ./LICENSE

Documentation

Overview

Package trie holds implementations of a simple trie and of a ternary search trie.

Package trie holds implementations of a simple trie and of a ternary search trie.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TernaryST

type TernaryST struct {
	// contains filtered or unexported fields
}

TernaryST is a symbol table specifically for string indexed keys.

func NewTernaryST

func NewTernaryST() *TernaryST

NewTernaryST creates a trie.

func (*TernaryST) Get

func (t *TernaryST) Get(key string) (interface{}, bool)

Get returns the value found at this location, if it exists

func (*TernaryST) Keys

func (t *TernaryST) Keys() []string

Keys returns all the keys known to this trie

func (*TernaryST) KeysMatching

func (t *TernaryST) KeysMatching(key string) []string

KeysMatching returns all the keys that share prefix `key`, where `key` can contain a wildcard character `.`.

func (*TernaryST) KeysWithPrefix

func (t *TernaryST) KeysWithPrefix(key string) []string

KeysWithPrefix returns all the keys starting with prefix `key`

func (*TernaryST) Len

func (t *TernaryST) Len() int

Len returns the count of elements in this trie

func (*TernaryST) LongestPrefix

func (t *TernaryST) LongestPrefix(key string) string

LongestPrefix returns the longest string in this trie that has `key` for prefix

func (*TernaryST) Put

func (t *TernaryST) Put(key string, val interface{})

Put puts the value `val` into the trie at key `key`.

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie is a symbol table specifically for string indexed keys.

func NewTrie

func NewTrie(offset byte, alphaSize uint8) *Trie

NewTrie creates a trie supporting alphabets of size `alphaSize`.

func (*Trie) Delete

func (t *Trie) Delete(key string)

Delete removes the value found at this location, if it exists

func (*Trie) Get

func (t *Trie) Get(key string) (interface{}, bool)

Get returns the value found at this location, if it exists

func (*Trie) Put

func (t *Trie) Put(key string, val interface{})

Put puts the value `val` into the trie at key `key`.

type TrieSet

type TrieSet struct {
	// contains filtered or unexported fields
}

TrieSet is a set of string backed by a trie structure.

func NewTrieSet

func NewTrieSet(offset rune, alphaSize uint8) *TrieSet

NewTrieSet creates a set supporting alphabets of size `alphaSize`.

func (*TrieSet) Add

func (t *TrieSet) Add(key string)

Add puts the key into the set.

func (*TrieSet) Contains

func (t *TrieSet) Contains(key string) bool

Contains tells if this key is in the set.

func (*TrieSet) Delete

func (t *TrieSet) Delete(key string)

Delete removes the key from the set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL