rbtree

package module
v0.0.0-...-9899538 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: GPL-2.0 Imports: 1 Imported by: 1

README

RbTree

Go Report Card GoDoc

Generic Red-Black Tree written in Go with generics.

Documentation

Index

Constants

View Source
const (
	RED   = 0
	BLACK = 1
)

color of node

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

type Tree[K Ordered, V any] struct {
	// contains filtered or unexported fields
}

Tree is a struct of red-black tree.

func NewTree

func NewTree[K Ordered, V any]() *Tree[K, V]

NewTree creates a new rbtree.

func (*Tree[K, V]) Clear

func (t *Tree[K, V]) Clear()

Clear destroys the rbtree.

func (*Tree[K, V]) Delete

func (t *Tree[K, V]) Delete(key K)

Delete deletes the node by key

func (*Tree[K, V]) Empty

func (t *Tree[K, V]) Empty() bool

Empty checks whether the rbtree is empty.

func (*Tree[K, V]) Find

func (t *Tree[K, V]) Find(key K) V

Find finds the node and return its value.

func (*Tree[K, V]) FindIt

func (t *Tree[K, V]) FindIt(key K) *node[K, V]

FindIt finds the node and return it as an iterator.

func (*Tree[K, V]) Insert

func (t *Tree[K, V]) Insert(key K, value V)

Insert inserts the key-value pair into the rbtree.

func (*Tree[K, V]) Iterator

func (t *Tree[K, V]) Iterator() *node[K, V]

Iterator creates the rbtree's iterator that points to the minmum node.

func (*Tree[K, V]) Size

func (t *Tree[K, V]) Size() int

Size returns the size of the rbtree.

Jump to

Keyboard shortcuts

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