trie

package
v0.0.0-...-89aa834 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package trie implements a prefix tree (trie) data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie represents a prefix tree data structure.

func New

func New() *Trie

New creates and returns a new Trie.

func (*Trie) Add

func (t *Trie) Add(word string)

Add inserts a word into the Trie.

func (*Trie) Has

func (t *Trie) Has(word string) bool

Has checks if the Trie contains the exact word.

func (*Trie) HasPrefix

func (t *Trie) HasPrefix(prefix string) bool

HasPrefix checks if the Trie contains any word with the given prefix.

func (*Trie) Remove

func (t *Trie) Remove(word string) bool

Remove deletes a word from the Trie if it exists. It returns true if the word was found and removed, false otherwise.

func (*Trie) Search

func (t *Trie) Search(prefix string, limit int) []string

Search retrieves words in the Trie that have the specified prefix. It returns up to 'limit' number of words. If limit is 0, it returns all matching words.

func (*Trie) SearchAppend

func (t *Trie) SearchAppend(dst []string, prefix string, limit int) []string

SearchAppend is similar to Search but appends the results to the provided slice. It returns the updated slice containing the matching words.

func (*Trie) String

func (t *Trie) String() string

String returns a string representation of the Trie.

func (*Trie) Stringify

func (t *Trie) Stringify(options *tree.Options) string

Stringify formats the Trie as a string using the provided options.

Jump to

Keyboard shortcuts

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