rbtree

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RBTree

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

func NewRBTree

func NewRBTree[T constraints.Ordered](allowDuplicates bool) *RBTree[T]

func NewRBTreeWithComparator

func NewRBTreeWithComparator[T comparable](comparator utility.Compare[T], allowDuplicates bool) *RBTree[T]

NewRBTreeWithComparator creates an empty tree with provided comparator for items.

func (*RBTree[T]) Empty

func (rbt *RBTree[T]) Empty() bool

func (*RBTree[T]) Erase

func (rbt *RBTree[T]) Erase(value T)

Erase deletes the item from the tree. Has no effect if the item was not in the tree. Complexity O(log n), where n is the number of elements in the tree.

func (*RBTree[T]) Find

func (rbt *RBTree[T]) Find(value T) (T, bool)

Find tries to find the value in the tree. Returns 2 values. First value is an item if it was found, otherwise zero value for type parameter. Second value is bool indicating whether an item was found. Complexity O(log n), where n is the number of elements in the tree.

func (*RBTree[T]) Insert

func (rbt *RBTree[T]) Insert(value T)

Insert adds value into the tree. Complexity O(log n), where n is the number of elements in the tree.

func (*RBTree[T]) Max

func (rbt *RBTree[T]) Max() T

Max returns max item in the tree according to the comparator. Complexity O(log n), where n is the number of elements in tree.

func (*RBTree[T]) Min

func (rbt *RBTree[T]) Min() T

Min returns min item in the tree according to the comparator Complexity O(log n), where n is the number of elements in the tree.

func (*RBTree[T]) Size

func (rbt *RBTree[T]) Size() int

Size return the number of elements in the tree. Complexity O(1).

Jump to

Keyboard shortcuts

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