prefixtree

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package prefixtree provides a basic prefix tree implementation.

Add, Has, HasPrefix, Delete and DeletePrefix are linear in query length, regardless of the size of the tree. All operations are non-recursive.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

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

A Tree is a prefix tree.

A zero value tree is invalid; use New to create a new instance.

func New

func New() *Tree

New returns an empty tree.

func (*Tree) Add

func (t *Tree) Add(x []byte)

Add inserts x to the tree. If a was already added, the tree is unchanged.

func (*Tree) Delete

func (t *Tree) Delete(x []byte) bool

Delete removes x from the tree, if possible. Returns the result of Has(a) before deletion.

func (*Tree) DeletePrefix

func (t *Tree) DeletePrefix(x []byte)

DeletePrefix removes prefix x from the tree. All sequences that have x as their prefix are removed. Other sequences are unchanged.

func (*Tree) FindPrefixes

func (t *Tree) FindPrefixes(x []byte) [][]byte

FindPrefixes returns all the elements in the tree that are prefixes of x, ordered by length.

func (*Tree) Has

func (t *Tree) Has(x []byte) bool

Has returns whether x was added to the tree.

func (*Tree) HasPrefix

func (t *Tree) HasPrefix(x []byte) bool

HasPrefix returns whether x is a prefix of an element in the tree.

func (*Tree) Iter

func (t *Tree) Iter() iter.Seq[[]byte]

Iter iterates over the elements of t, in no particular order. The tree should not be modified during iteration.

func (*Tree) IterPrefix

func (t *Tree) IterPrefix(x []byte) iter.Seq[[]byte]

IterPrefix iterates the elements in the tree that have x as their prefix. Calling IterPrefix with a zero-length slice is equivalent to Iter().

Jump to

Keyboard shortcuts

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