aatree

package
v0.1.63 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 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 AATree

type AATree[X any] struct {
	// contains filtered or unexported fields
}

AATree represents an AA tree structure. The generic type X is the type of data stored in the tree.

func New added in v0.1.34

func New[X any](compare CompareFunc[X]) *AATree[X]

New creates a new, empty AA tree with the given comparison function.

func (*AATree[X]) After added in v0.1.34

func (t *AATree[X]) After(data X) (X, bool)

After finds the node immediately after the passed data. It returns a pointer to the data, or nil if not found or tree is empty.

func (*AATree[X]) Before

func (t *AATree[X]) Before(data X) (X, bool)

Before finds the node immediately before the passed data. It returns a pointer to the data, or nil if not found or tree is empty.

func (*AATree[X]) Clear

func (t *AATree[X]) Clear()

Clear removes all elements from the tree.

func (*AATree[X]) Count

func (t *AATree[X]) Count() int

Count returns the number of items in this tree.

func (*AATree[X]) EqualAfter added in v0.1.34

func (t *AATree[X]) EqualAfter(data X) (X, bool)

EqualAfter finds the node with the given data or the node closest above the passed argument. It returns a pointer to the data, or nil if not found or tree is empty.

func (*AATree[X]) EqualBefore added in v0.1.34

func (t *AATree[X]) EqualBefore(data X) (X, bool)

EqualBefore finds the node with the given data or the node closest before the passed argument. It returns a pointer to the data, or nil if not found or tree is empty.

func (*AATree[X]) Get added in v0.1.34

func (t *AATree[X]) Get(data X) (out X, ok bool)

Get checks if this tree contains the given data, based on the compare function. Returns the previously added data for this node.

func (*AATree[X]) Has

func (t *AATree[X]) Has(data X) bool

Has checks if this tree contains the given data, based on the compare function.

func (*AATree[X]) High added in v0.1.34

func (t *AATree[X]) High() (out X, ok bool)

High returns the low node from this tree.

func (*AATree[X]) Insert

func (t *AATree[X]) Insert(data X) bool

Insert inserts the value into the tree. It updates the previous value if the compare function returns zero. Returns true if a new node was inserted. This returns false if the node already existed, however, the data might still have changed (it just compared as equal).

func (*AATree[X]) Iter added in v0.1.34

func (t *AATree[X]) Iter() iter.Seq[X]

Iter iterates over all data here.

func (*AATree[X]) Low added in v0.1.34

func (t *AATree[X]) Low() (out X, ok bool)

Low returns the low node from this tree.

func (*AATree[X]) Remove

func (t *AATree[X]) Remove(data X) bool

Remove removes the value from the tree. Returns true if there was a change (node was removed), false otherwise.

type CompareFunc

type CompareFunc[X any] func(a, b X) int

CompareFunc is a function type that compares two elements of type X. It should return:

  • a negative integer if a < b
  • zero if a == b
  • a positive integer if a > b

Jump to

Keyboard shortcuts

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