container

package
v1.6.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValue

type KeyValue[T any] struct {
	Key   string
	Value T
}

KeyValue represents a key-value pair in the trie

type Trie

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

Trie implements a prefix tree optimized for memory usage with shared prefixes

func NewTrie

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

NewTrie creates a new Trie instance

func (*Trie[T]) Delete

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

Delete removes a key-value pair from the trie Time complexity: O(k * log n) where k is the number of parts in the key and n is the average number of children per node

func (*Trie[T]) Get

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

Get retrieves a value from the trie Time complexity: O(k * log n) where k is the number of parts in the key and n is the average number of children per node

func (*Trie[T]) GetByPrefix

func (t *Trie[T]) GetByPrefix(prefix string) []KeyValue[T]

GetByPrefix returns all key-value pairs with the given prefix Time complexity: O(k * log n + m) where k is the number of parts in the prefix, n is the average number of children per node, and m is the number of matching nodes

func (*Trie[T]) Insert

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

Insert adds or updates a value in the trie Time complexity: O(k * log n) where k is the number of parts in the key and n is the average number of children per node

func (*Trie[T]) Size

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

Size returns the number of key-value pairs in the trie

type TrieNode

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

TrieNode represents a node in the trie

Jump to

Keyboard shortcuts

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