avl

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

type Tree[K cmp.Ordered, V any] interface {
	// Each traverses the tree in order and calls the given function for each node.
	Each(func(K, V) bool)
	// Insert inserts a key-value pair and returns the previous value if it exists.
	Insert(K, V) V
	// Delete removes a node with the given key from the AVL tree.
	Delete(K) bool
	// Pop removes a node with the given key from the AVL tree and returns the value.
	Pop(K) (V, bool)
	// Find returns the value associated with the given key.
	Find(K) (V, bool)
	// RootKeyValue returns the key and value of the root node.
	RootKeyValue() (K, V, bool)
	// Length returns the length of the tree.
	Length() int
	// Height returns the height of the tree.
	Height() int
	// Clear removes all nodes from the tree.
	Clear()
	// Empty returns true if the tree is empty.
	Empty() bool
	// Clone returns a copy of the tree.
	Clone() Tree[K, V]
}

Tree represents an AVL tree.

func NewTree

func NewTree[K cmp.Ordered, V any]() Tree[K, V]

func NewTreeFromLeft

func NewTreeFromLeft[K cmp.Ordered, V any](t Tree[K, V]) Tree[K, V]

func NewTreeFromRight

func NewTreeFromRight[K cmp.Ordered, V any](t Tree[K, V]) Tree[K, V]

Jump to

Keyboard shortcuts

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