trie

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

https://github.com/derekparker/trie/blob/v3/trie.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByKeys

type ByKeys []string

func (ByKeys) Len

func (a ByKeys) Len() int

func (ByKeys) Less

func (a ByKeys) Less(i, j int) bool

func (ByKeys) Swap

func (a ByKeys) Swap(i, j int)

type Node

type Node[T any] interface {
	Value() T
}

type Trie

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

Trie is a data structure that stores a set of strings.

func New

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

New creates a new Trie with an initialized root Node.

func (*Trie[T]) Add

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

Add adds the key to the Trie, including value data

func (*Trie[T]) Find

func (t *Trie[T]) Find(key string) (Node[T], bool)

Find finds and returns value data associated with `key`.

func (*Trie[T]) FuzzySearch

func (t *Trie[T]) FuzzySearch(pre string) []string

FuzzySearch performs a fuzzy search against the keys in the trie.

func (*Trie[T]) HasKeysWithPrefix

func (t *Trie[T]) HasKeysWithPrefix(key string) bool

func (*Trie[T]) Keys

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

Keys returns all the keys currently stored in the trie.

func (*Trie[T]) PrefixSearch

func (t *Trie[T]) PrefixSearch(pre string) []string

PrefixSearch performs a prefix search against the keys in the trie.

func (*Trie[T]) Remove

func (t *Trie[T]) Remove(key string)

Remove removes a key from the trie, ensuring that all bitmasks up to root are appropriately recalculated.

Jump to

Keyboard shortcuts

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