avl

package
v0.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const Unbounded int64 = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type AVL

type AVL[T comparable] struct {
	// contains filtered or unexported fields
}

Basic AVL tree implementation.

Nodes require an ID (for example a job ID) for insertion. The ID itself is not used for any balancing. IDs are assumed to be unique.

It supports multiple nodes with the same values. Hence why retrieving a value bases bases around ranges.

func (*AVL[T]) Add

func (a *AVL[T]) Add(id T, v int64)

Add adds the value v to the node with ID id and recomputes the tree.

func (*AVL[T]) Delete

func (a *AVL[T]) Delete(id T)

func (AVL[T]) Fairshare

func (a AVL[T]) Fairshare(cap int64) int64

Fairshare determines the maximum allowed capacity for all added nodes to be fairshared.

func (AVL[T]) Get

func (a AVL[T]) Get(id T) *Node[T]

func (AVL[T]) GraphDot

func (a AVL[T]) GraphDot() string

func (*AVL[T]) Insert

func (a *AVL[T]) Insert(id T, v int64)

func (AVL[T]) Len

func (a AVL[T]) Len() int64

func (AVL[T]) Range

func (a AVL[T]) Range(from, to int64) iter.Seq[*Node[T]]

Range returns an iterator of nodes with values in the range [from, to). avl.Unbounded may be passed in to either argument to include all elements from either range.

func (*AVL[T]) Replace

func (a *AVL[T]) Replace(id T, newV int64)

Replace deletes any old nodes with the given id if they exist, and inserts a completely new node with the new value. Preferred over Insert if it's not clear if the id has already been inserted.

func (AVL[T]) String

func (a AVL[T]) String() string

func (AVL[T]) Sum

func (a AVL[T]) Sum() int64

type Node

type Node[T comparable] struct {
	ID T

	// h is the height of its children. 0 if it has no children.
	Value        int64
	Parent, L, R *Node[T]
	// contains filtered or unexported fields
}

func (Node[T]) Detailed

func (n Node[T]) Detailed() string

func (Node[T]) GraphDot

func (n Node[T]) GraphDot() string

func (Node[T]) String

func (n Node[T]) String() string

Jump to

Keyboard shortcuts

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