Documentation ¶
Overview ¶
Package avl - an AVL balanced tree with the addition of parent pointers to allow iteration through the nodes
Note: an individual tree is not thread safe, so either access only
in a single go routine or use mutex/rwmutex to restrict access.
The base algorithm was described in an old book by Niklaus Wirth called Algorithms + Data Structures = Programs.
This version allows for data associated with key, which can be overwritten by an insert with the same key. Also delete no does not copy data around so that previous nodes can be deleted during iteration.
Index ¶
- type Item
- type Node
- type Tree
- func (tree *Tree) CheckCounts() bool
- func (tree *Tree) CheckUp() bool
- func (tree *Tree) Count() int
- func (tree *Tree) Delete(key Item) interface{}
- func (tree *Tree) First() *Node
- func (tree *Tree) Get(index int) *Node
- func (tree *Tree) Insert(key Item, value interface{}) bool
- func (tree *Tree) IsEmpty() bool
- func (tree *Tree) Last() *Node
- func (tree *Tree) Print(printData bool) int
- func (tree *Tree) Root() *Node
- func (tree *Tree) Search(key Item) (*Node, int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶ added in v0.11.0
type Item interface {
Compare(interface{}) int // for left/right ordering of items
}
Item - a key item must implement the Compare function
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node - a node in the tree
func (*Node) GetChildrenByDepth ¶ added in v0.3.30
GetChildrenByDepth - returns all children in a specific depth of a tree
func (*Node) Next ¶
Next - given a node, return the node with the next highest key value or nil if no more nodes.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree - type to hold the root node of a tree
func (*Tree) CheckCounts ¶ added in v0.7.0
CheckCounts - check left and right node counts are ok