tree

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: Apache-2.0 Imports: 0 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 struct {
	Val     rune           // The value of the node
	Depth   int            // The depth of the node in the tree
	Count   int            // Counts the number of branches
	Payload interface{}    // The payload associated with the node
	Child   map[rune]*Node // Children of the node, mapped by rune
	IsWord  bool           // Flag indicating if this node marks the end of a complete string
}

func NewNode

func NewNode() *Node

NewNode new node

type Trie

type Trie struct {
	Root *Node
}

func NewTrie

func NewTrie() *Trie

func (*Trie) Del

func (t *Trie) Del(str string)

Del deletion of a node has the following cases:

  1. Prefix deletion: Check if Count is greater than 0, then set IsWord to false.
  2. String deletion: a. If there is no branching, delete the entire string. b. If there is branching, only delete the part that is not a common prefix.

func (*Trie) Find

func (t *Trie) Find(str string) (bool, interface{})

func (*Trie) FindAll

func (t *Trie) FindAll(prefix string) []any

FindAll finds all strings that start with the given prefix and returns their payloads.

func (*Trie) Insert

func (t *Trie) Insert(str string, p any)

Insert node

Jump to

Keyboard shortcuts

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