aatree

package
v0.1.33 Latest Latest
Warning

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

Go to latest
Published: May 11, 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 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 NewAATree

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

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

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]) Find

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

Find 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]) 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]) 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 there was a change (new node inserted or existing node updated), false otherwise.

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