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 ¶
- type RBTree
- func (rbTree *RBTree[Value]) All() iter.Seq[Value]
- func (rbTree *RBTree[Value]) Count() int
- func (rbTree *RBTree[Value]) Delete(value Value) (newTree *RBTree[Value], affected bool)
- func (rbTree *RBTree[Value]) Empty() bool
- func (rbTree *RBTree[Value]) InorderTraversal() iter.Seq[Value]
- func (rbTree *RBTree[Value]) Insert(value Value) (newTree *RBTree[Value], affected bool)
- func (rbTree *RBTree[Value]) Lookup(value Value) *Value
- func (rbTree *RBTree[Value]) Maximum() Value
- func (rbTree *RBTree[Value]) Minimum() Value
- func (rbTree *RBTree[Value]) Values() []Value
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]) Delete ¶
`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]) InorderTraversal ¶
func (*RBTree[Value]) Insert ¶
`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]) Maximum ¶
func (rbTree *RBTree[Value]) Maximum() Value
CAUTION: Only invoke `Maximum` with non-empty RBTree.