redblackhash

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: GPL-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package redblacktree implements a red-black tree.

Used by TreeSet and TreeMap.

Structure is not thread safe.

References: http://en.wikipedia.org/wiki/Red%E2%80%93black_tree

Index

Constants

View Source
const (
	KeySize = 64
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key [KeySize]byte

func (*Key) Compare

func (k *Key) Compare(o *Key) int

type Node

type Node struct {
	Key Key

	Left   *Node
	Right  *Node
	Parent *Node
	// contains filtered or unexported fields
}

Node is a single element within the tree

func (*Node) String

func (node *Node) String() string

type Tree

type Tree struct {
	sync.Mutex
	Root *Node
	// contains filtered or unexported fields
}

Tree holds elements of the red-black tree

func (*Tree) Ceiling

func (tree *Tree) Ceiling(key *Key) (ceiling *Node, found bool)

Ceiling finds ceiling node of the input key, return the ceiling node or nil if no ceiling is found. Second return parameter is true if ceiling was found, otherwise false.

Ceiling node is defined as the smallest node that is larger than or equal to the given node. A ceiling node may not be found, either because the tree is empty, or because all nodes in the tree are smaller than the given node.

Key should adhere to the comparator's type assertion, otherwise method panics.

func (*Tree) Clear

func (tree *Tree) Clear()

Clear removes all nodes from the tree.

func (*Tree) Empty

func (tree *Tree) Empty() bool

Empty returns true if tree does not contain any nodes

func (*Tree) Floor

func (tree *Tree) Floor(key *Key) (floor *Node, found bool)

Floor Finds floor node of the input key, return the floor node or nil if no floor is found. Second return parameter is true if floor was found, otherwise false.

Floor node is defined as the largest node that is smaller than or equal to the given node. A floor node may not be found, either because the tree is empty, or because all nodes in the tree are larger than the given node.

Key should adhere to the comparator's type assertion, otherwise method panics.

func (*Tree) Get

func (tree *Tree) Get(key *Key) (found bool)

Get searches the node in the tree by key and returns its value or nil if key is not found in tree. Second return parameter is true if key was found, otherwise false. Key should adhere to the comparator's type assertion, otherwise method panics.

func (*Tree) Left

func (tree *Tree) Left() *Node

Left returns the left-most (min) node or nil if tree is empty.

func (*Tree) Put

func (tree *Tree) Put(key *Key)

Put inserts node into the tree. Key should adhere to the comparator's type assertion, otherwise method panics.

func (*Tree) Remove

func (tree *Tree) Remove(key *Key)

Remove remove the node from the tree by key. Key should adhere to the comparator's type assertion, otherwise method panics.

func (*Tree) Right

func (tree *Tree) Right() *Node

Right returns the right-most (max) node or nil if tree is empty.

func (*Tree) Size

func (tree *Tree) Size() int

Size returns number of nodes in the tree.

func (*Tree) String

func (tree *Tree) String() string

String returns a string representation of container

Jump to

Keyboard shortcuts

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