immutable_rb_tree

package
v0.0.0-...-b6e66c0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Implementation of Red-Black Trees in a Functional Setting

References: - Insertion: https://www.cs.tufts.edu/comp/150FP/archive/chris-okasaki/redblack99.pdf - Deletion: https://matt.might.net/articles/red-black-delete/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RBTree

type RBTree[Value any] struct {
	// contains filtered or unexported fields
}

The zero value of `RBTree` makes nonsense.

func FromValues

func FromValues[Value any](cmp comparator.Comparator[Value], values ...Value) *RBTree[Value]

func New

func New[Value any](cmp comparator.Comparator[Value]) *RBTree[Value]

func (*RBTree[Value]) All

func (rbTree *RBTree[Value]) All() iter.Seq[Value]

`All()` Returns an iterator of all values in an in-order traversal.

func (*RBTree[Value]) Count

func (rbTree *RBTree[Value]) Count() int

func (*RBTree[Value]) Delete

func (rbTree *RBTree[Value]) Delete(value Value) (newTree *RBTree[Value], affected bool)

`affected` is true, meaning that a real deletion occurred, `newTree` will be different from the original; otherwise nothing happens, `newTree` is the original one.

func (*RBTree[Value]) Empty

func (rbTree *RBTree[Value]) Empty() bool

func (*RBTree[Value]) InorderTraversal

func (rbTree *RBTree[Value]) InorderTraversal() iter.Seq[Value]

func (*RBTree[Value]) Insert

func (rbTree *RBTree[Value]) Insert(value Value) (newTree *RBTree[Value], affected bool)

`newTree` returned by `Insert()` is always different from the original one. `affected` is true, meaning an actual insertion occurred; otherwise, a replacement occurred.

func (*RBTree[Value]) Lookup

func (rbTree *RBTree[Value]) Lookup(value Value) *Value

func (*RBTree[Value]) Maximum

func (rbTree *RBTree[Value]) Maximum() Value

CAUTION: Only invoke `Maximum` with non-empty RBTree.

func (*RBTree[Value]) Minimum

func (rbTree *RBTree[Value]) Minimum() Value

CAUTION: Only invoke `Minimum` with non-empty RBTree.

func (*RBTree[Value]) Values

func (rbTree *RBTree[Value]) Values() []Value

Jump to

Keyboard shortcuts

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