trie

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 5 Imported by: 1

README

License Build Go Report Card Maintainability Test Coverage

PkgGoDev Go Version Tag

trie

Generic prefix tree for golang

example

    import (
        "fmt"
        "log"

        "github.com/s0rg/trie"
    )

    t := trie.New[int]()

    t.Add("bar", 1)
    t.Add("baz", 2)
    t.Add("bat", 3)

    val, err := t.Find("bar")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(val) // will print 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
	ErrNoValue  = errors.New("empty value")
)

Functions

This section is empty.

Types

type Trie

type Trie[T any] struct {
	// contains filtered or unexported fields
}

Trie represents generic prefix-tree.

func New

func New[T any]() *Trie[T]

New creates empty Trie.

func (*Trie[T]) Add

func (t *Trie[T]) Add(key string, value T)

Add inserts new key/value pair.

func (*Trie[T]) Del

func (t *Trie[T]) Del(key string) (err error)

Del removes node by key.

func (*Trie[T]) Find

func (t *Trie[T]) Find(key string) (value T, err error)

Find does tree-lookup in order to find value associated with given key.

func (*Trie[T]) String

func (t *Trie[T]) String() string

String implements fmt.Stringer interface.

Jump to

Keyboard shortcuts

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