trie

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: Apache-2.0 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[T any] struct {
	// contains filtered or unexported fields
}

func (*Node[T]) Count

func (n *Node[T]) Count() int

func (*Node[T]) Equal added in v0.0.2

func (n *Node[T]) Equal(other *Node[T], equalFn func(a T, b T) bool) bool

func (*Node[T]) GetAllLeafs

func (n *Node[T]) GetAllLeafs() []T

func (*Node[T]) GetClosestNode added in v0.0.2

func (n *Node[T]) GetClosestNode(keyParts []string) *Node[T]

func (*Node[T]) GetNode added in v0.0.2

func (n *Node[T]) GetNode(keyParts []string) (*Node[T], bool)

func (*Node[T]) Iterate

func (n *Node[T]) Iterate(f func(key string, value T))

type Trie

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

Trie is a simplified version of a Radix tree (https://en.wikipedia.org/wiki/Radix_tree#:~:text=In%20computer%20science%2C%20a%20radix,is%20merged%20with%20its%20parent.) Trie can be used to search for objects based on a key prefix To improve performance, the key is split by a separator instead of a common characters.

func FromMap added in v0.0.2

func FromMap[T any](keySeparator string, m map[string]T) *Trie[T]

func New

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

New creates a new (Radix) Trie

func (*Trie[T]) Equal added in v0.0.2

func (t *Trie[T]) Equal(other *Trie[T], equalFn func(a T, b T) bool) bool

func (*Trie[T]) Get added in v0.0.2

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

Get returns the value for a given key

func (*Trie[T]) GetClosest added in v0.0.2

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

GetClosest returns the value for the closest key

func (*Trie[T]) Insert

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

Insert a new value with given key

func (*Trie[T]) Iterate added in v0.0.2

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

func (*Trie[T]) SearchPrefix

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

SearchPrefix search for all values that within the data structure with a given prefix Note that the prefix key will be split by the separator

func (*Trie[T]) Size

func (t *Trie[T]) Size() int

Jump to

Keyboard shortcuts

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