trie

package
v0.0.0-...-5d524ee Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node[V any] struct {
	// contains filtered or unexported fields
}

Node is a node in the Trie.

func (*Node[V]) Next

func (n *Node[V]) Next(r rune) RuneFinder[V]

func (*Node[V]) Value

func (n *Node[V]) Value() (V, bool)

type RuneFinder

type RuneFinder[V any] interface {
	// Next returns the next node in the tree for the given rune
	// or nil if no such node exists.
	Next(r rune) RuneFinder[V]

	// Value returns the value stored at this node.
	Value() (value V, found bool)
}

type Trie

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

Trie is a tree data structure that stores strings against values.

The trie (prefix tree) allows for character by character lookup of a string.

func New

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

New creates a new Trie.

func (*Trie[V]) Find

func (t *Trie[V]) Find(key string) (value V, found bool)

Find returns the value for the given key, or false if the key does not exist.

func (*Trie[V]) Insert

func (t *Trie[V]) Insert(key string, value V) error

Insert inserts a new key/value pair into the Trie.

It returns an error if the key already exists.

func (*Trie[V]) MustInsert

func (t *Trie[V]) MustInsert(key string, value V) *Trie[V]

MustInsert inserts a new key/value pair into the Trie, however unlike [Insert], it panics if the key already exists.

func (*Trie[V]) Next

func (t *Trie[V]) Next(r rune) RuneFinder[V]

func (*Trie[V]) SubstrMatches

func (t *Trie[V]) SubstrMatches(text string) (values []V)

SubstrMatches returns all the matches within the given text in the order that they where found.

If there are multiple overlapping matches, all will be returned.

func (*Trie[V]) Value

func (t *Trie[V]) Value() (V, bool)

Jump to

Keyboard shortcuts

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