Documentation ¶
Overview ¶
Package avltree implements a generic AVL tree.
Index ¶
- func CmpOrd[T cmp.Ordered](a, b T) int
- type Cmp
- type Tree
- func (t *Tree[T]) Add(v T) bool
- func (t *Tree[T]) Clone() *Tree[T]
- func (t *Tree[T]) Contains(v T) bool
- func (t *Tree[T]) Count() int
- func (t *Tree[T]) Del(v T) bool
- func (t *Tree[T]) Each(fn func(v T))
- func (t *Tree[T]) Get(v T) (T, bool)
- func (t *Tree[T]) GetAll(v T) []T
- func (t *Tree[T]) IsEmpty() bool
- func (t *Tree[T]) Slice() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Tree ¶
type Tree[T any] struct { // contains filtered or unexported fields }
An AVL tree.
func New ¶
New creates a new, empty AVL tree. The function cmp is used for comparing values while navigating the tree. If nodups is true, no duplicate values are allowed and Add() will return false if the value is already present. Panics if cmp is nil.
func (*Tree[T]) Clone ¶ added in v0.2.0
Clone clones the tree. This method only makes shallow copies of the values.
func (*Tree[T]) Each ¶
func (t *Tree[T]) Each(fn func(v T))
Each traverses the tree in-order and applies fn to each value.
func (*Tree[T]) Get ¶ added in v0.3.0
Get gets the first value that is equal to v regarding the Cmp function.
func (*Tree[T]) GetAll ¶ added in v0.3.0
func (t *Tree[T]) GetAll(v T) []T
GetAll gets all values that are equal to v regarding the Cmp function.
Click to show internal directories.
Click to hide internal directories.