redblacktree

package
v0.0.0-...-1974178 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0, BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a Node in the RedBlackTree.

func (*Node) GrandParent

func (n *Node) GrandParent() *Node

GrandParent returns the parent of the parent Node (or nil if it does not exist).

func (*Node) IsBlack

func (n *Node) IsBlack() bool

IsBlack returns true if the Node is marked as black (colors are used for the self-balancing properties of the RedBlackTree).

func (*Node) Key

func (n *Node) Key() interface{}

Key returns the key that is used to identify the Node.

func (*Node) Max

func (n *Node) Max() (node *Node)

Max returns the largest of all descendants of the Node.

func (*Node) Min

func (n *Node) Min() (node *Node)

Min returns the smallest of all descendants of the Node.

func (*Node) Parent

func (n *Node) Parent() *Node

Parent returns the parent of the Node (or nil if the Node is the root of the RedBlackTree).

func (*Node) Predecessor

func (n *Node) Predecessor() *Node

Predecessor returns the Node with the next lower key (or nil if none exists).

func (*Node) Sibling

func (n *Node) Sibling() *Node

Sibling returns the alternative Node sharing the same parent Node.

func (*Node) String

func (n *Node) String() string

String returns a human readable version of the Node.

func (*Node) Successor

func (n *Node) Successor() *Node

Successor returns the Node with the next highest key (or nil if none exists).

func (*Node) Uncle

func (n *Node) Uncle() *Node

Uncle returns the sibling of the parent Node.

func (*Node) Value

func (n *Node) Value() interface{}

Value returns the value that is associated to the Node.

type RedBlackTree

type RedBlackTree struct {
	// contains filtered or unexported fields
}

RedBlackTree represents a self balancing binary search tree, that can be used to efficiently look up value associated to a set of keys.

func New

func New(optionalComparator ...genericcomparator.Type) *RedBlackTree

New creates a new red-black RedBlackTree that uses the given comparator (or the default Comparator if the parameter is omitted) to compare the keys used to identify the nodes.

func (*RedBlackTree) Ceiling

func (t *RedBlackTree) Ceiling(key interface{}) (ceiling *Node)

Ceiling returns the Node with the smallest key that is >= the given key (or nil if no ceiling was found).

func (*RedBlackTree) Clear

func (t *RedBlackTree) Clear()

Clear removes all Nodes from the RedBlackTree.

func (*RedBlackTree) Delete

func (t *RedBlackTree) Delete(key interface{}) (node *Node, success bool)

Delete removes a Node belonging to the given key from the RedBlackTree and returns it (if it existed) together with a flag that indicates if it existed.

func (*RedBlackTree) DeleteNode

func (t *RedBlackTree) DeleteNode(node *Node)

DeleteNode removes the Node from the RedBlackTree (which can be i.e. useful for modifying the RedBlackTree while iterating.

func (*RedBlackTree) Empty

func (t *RedBlackTree) Empty() bool

Empty returns true if the RedBlackTree has no Nodes.

func (*RedBlackTree) Floor

func (t *RedBlackTree) Floor(key interface{}) (floor *Node)

Floor returns the Node with the largest key that is <= the given key (or nil if no floor was found).

func (*RedBlackTree) ForEach

func (t *RedBlackTree) ForEach(iterator func(node *Node) bool)

ForEach iterates through the Nodes of the RedBlackTree in ascending order and calls the iterator function for each Node. The iteration aborts as soon as the iterator function returns false.

func (*RedBlackTree) Get

func (t *RedBlackTree) Get(key interface{}) (value interface{}, found bool)

Get returns the value stored with the given key (or nil if the value does not exist with found being false).

func (*RedBlackTree) Keys

func (t *RedBlackTree) Keys() (keys []interface{})

Keys returns an ordered list of keys that are stored in the RedBlackTree.

func (*RedBlackTree) Max

func (t *RedBlackTree) Max() *Node

Max returns the Node with the largest key (or nil if the RedBlackTree is empty).

func (*RedBlackTree) Min

func (t *RedBlackTree) Min() *Node

Min returns the Node with the smallest key (or nil if the RedBlackTree is empty).

func (*RedBlackTree) Node

func (t *RedBlackTree) Node(key interface{}) (node *Node)

Node returns the Node that belongs to the given key (or nil if it doesn't exist).

func (*RedBlackTree) Set

func (t *RedBlackTree) Set(key interface{}, value interface{}) (node *Node, inserted bool)

Set inserts or updates a Node in the RedBlackTree and returns it together with a flag that indicates if it was inserted.

func (*RedBlackTree) Size

func (t *RedBlackTree) Size() int

Size returns the amount of Nodes in the RedBlackTree.

func (*RedBlackTree) String

func (t *RedBlackTree) String() string

String returns a human readable version of the RedBlackTree.

func (*RedBlackTree) Values

func (t *RedBlackTree) Values() (values []interface{})

Values returns an ordered list of values that are stored in the RedBlackTree.

Jump to

Keyboard shortcuts

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