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 ¶
- type Node
- type Tree
- func (tree *Tree) Clear()
- func (tree *Tree) Empty() bool
- func (tree *Tree) Get(key interface{}) (values []Value, found bool)
- func (tree *Tree) Left() (key interface{}, values []Value)
- func (tree *Tree) PopLeft() (key interface{}, values []Value)
- func (tree *Tree) PopRight() (key interface{}, values []Value)
- func (tree *Tree) Put(key interface{}, value Value)
- func (tree *Tree) Remove(key interface{})
- func (tree *Tree) Right() (key interface{}, values []Value)
- func (tree *Tree) Size() int
- func (tree *Tree) String() string
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct { Key interface{} Values []Value Left *Node Right *Node Parent *Node // contains filtered or unexported fields }
Node is a single element within the tree
type Tree ¶
type Tree struct { Root *Node Comparator utils.Comparator // contains filtered or unexported fields }
Tree holds elements of the red-black tree
func NewWith ¶
func NewWith(comparator utils.Comparator) *Tree
NewWith instantiates a red-black tree with the custom comparator.
func (*Tree) Get ¶
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) Put ¶
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 interface{})
Remove remove the node from the tree by key. Key should adhere to the comparator's type assertion, otherwise method panics.