rbtree

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2016 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package rbtree provides an implementation of a Red Black Tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RBIter

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

An RBIter iterates over nodes in an RBTree

func NewRBIter

func NewRBIter(tree *RBTree) *RBIter

NewRBIter returns an RBIter for the given tree, or nil if the given tree is nil

func NewRBIterAt

func NewRBIterAt(tree *RBTree, val int) *RBIter

NewRBIterAt returns an RBIter for the given tree at or immediately after the given val, or nil if the tree, or the tree's root, is nil

func (*RBIter) Next

func (i *RBIter) Next() *RBNode

Next returns the next node in the tree

func (*RBIter) Nil

func (i *RBIter) Nil() bool

Nil returns true if the current node is nil

func (*RBIter) Str

func (i *RBIter) Str() string

Str returns the str contained at the current node

func (*RBIter) Val

func (i *RBIter) Val() int

Val returns the val contained at the current node

type RBNode

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

An RBNode is a node in the RBTree

func (*RBNode) Child

func (n *RBNode) Child(right bool) *RBNode

Child returns the left or right node of the RBTree

func (*RBNode) Str

func (n *RBNode) Str() string

Str returns the str contained in the node

func (*RBNode) Val

func (n *RBNode) Val() int

Val returns the val contained in the node

type RBTree

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

An RBTree is an automatically balancing tree of KVP pairs (presumably)

func (*RBTree) Delete

func (t *RBTree) Delete(val int) bool

Delete removes a value from the RBTree Returns true on succesful deletion, false if val is not in tree

func (*RBTree) Insert

func (t *RBTree) Insert(val int, str string) (ret bool)

Insert inserts a value and string into the tree Returns true on succesful insertion, false if duplicate exists

func (*RBTree) Iter

func (t *RBTree) Iter() *RBIter

Iter returns an iterator starting at the leftmost node in the tree

func (*RBTree) IterAt

func (t *RBTree) IterAt(val int) *RBIter

IterAt returns an iter set at, or immediately after, val

func (*RBTree) Search

func (t *RBTree) Search(val int) (string, bool)

Search searches for a value in the RBTree, returns the string and true if found, or the empty string and false if val is not in the tree

func (*RBTree) Size

func (t *RBTree) Size() int

Size returns the number of nodes in the RBTree

Jump to

Keyboard shortcuts

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