Documentation
¶
Overview ¶
Package rbtree implements Red-Black tree data structure (RB-Tree).
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrorFromGreaterThanToKey error = errors.New("fromKey should be >= toKey")
ErrorFromGreaterThanToKey informs that the fromKey should be less or equal to toKey
View Source
var ErrorOutOfSubTreeRange error = errors.New("Given key is out of sub tree range")
ErrorOutOfSubTreeRange tells that there was an attempt to access out of the subtree range.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item interface {
// Less tells whether the current element is less than the given argument.
Less(other Item) bool
}
Item represents a single object in the tree.
type Iterator ¶
type Iterator interface {
// IsValid returns true if the iterator is valid, otherwise returns false.
IsValid() bool
// Next moves the iterator to the next element and returns it.
Next() Item
// Get returns the current pointed element. Return nil if the iterator is invalid.
Get() Item
}
Iterator represents an iterator over a tree collection which provides inorder traverse.
type Tree ¶
type Tree interface {
// Returns the number of items in the tree.
Len() int
// Insert adds the given item to the tree.
// Returns true if the item was successfully inserted, or returns false if the item was replaced.
// Returns an error if there was an attempt to add an element out of subtree range.
Insert(item Item) (bool, error)
// Remove deletes an item equals to the given item from the tree.
// Returns true if the item was successfully removes, otherwise returns false.
// Returns an error if there was an attempt to remove an element out of subtree range.
Remove(item Item) (bool, error)
// Returns the item if the given key is in the tree, otherwise return nil.
Find(item Item) Item
// Returns the min element in the tree.
Min() Item
// Returns the max element in the tree.
Max() Item
// Returns an iterator that points at the smallest element in the tree.
NewIterator() Iterator
// SubTree returns a view of the portion of this tree whose keys range from
// fromKey, inclusive, to toKey, exclusive.
SubTree(fromKey Item, toKey Item) (Tree, error)
}
Tree represents Red-Black tree.
Click to show internal directories.
Click to hide internal directories.