Documentation
¶
Overview ¶
A Left-Leaning Red-Black (LLRB) implementation of 2-3 balanced binary search trees, based on the following work:
http://www.cs.princeton.edu/~rs/talks/LLRB/08Penn.pdf http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf http://www.cs.princeton.edu/~rs/talks/LLRB/Java/RedBlackBST.java 2-3 trees (and the run-time equivalent 2-3-4 trees) are the de facto standard BST algoritms found in implementations of Python, Java, and other libraries. The LLRB implementation of 2-3 trees is a recent improvement on the traditional implementation, observed and documented by Robert Sedgewick.
Index ¶
- type Int
- type Item
- type ItemIterator
- type LLRB
- func (t *LLRB) AscendGreaterOrEqual(pivot Item, iterator ItemIterator)
- func (t *LLRB) AscendLessThan(pivot Item, iterator ItemIterator)
- func (t *LLRB) AscendRange(greaterOrEqual, lessThan Item, iterator ItemIterator)
- func (t *LLRB) Delete(key Item) (deleted Item, pos int)
- func (t *LLRB) DeleteMax() Item
- func (t *LLRB) DeleteMin() Item
- func (t *LLRB) DescendLessOrEqual(pivot Item, iterator ItemIterator)
- func (t *LLRB) Get(key Item) Item
- func (t *LLRB) GetHeight(key Item) (result Item, depth int)
- func (t *LLRB) Has(key Item) bool
- func (t *LLRB) HeightStats() (avg, stddev float64)
- func (t *LLRB) InsertNoReplace(item Item) int
- func (t *LLRB) InsertNoReplaceBulk(items ...Item)
- func (t *LLRB) Len() int
- func (t *LLRB) Max() Item
- func (t *LLRB) Min() Item
- func (t *LLRB) ReplaceOrInsert(item Item) (Item, int)
- func (t *LLRB) ReplaceOrInsertBulk(items ...Item)
- func (t *LLRB) Root() *Node
- func (t *LLRB) SetRoot(r *Node)
- type Node
- type String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ItemIterator ¶
type LLRB ¶
type LLRB struct {
// contains filtered or unexported fields
}
Tree is a Left-Leaning Red-Black (LLRB) implementation of 2-3 trees
func (*LLRB) AscendGreaterOrEqual ¶
func (t *LLRB) AscendGreaterOrEqual(pivot Item, iterator ItemIterator)
AscendGreaterOrEqual will call iterator once for each element greater or equal to pivot in ascending order. It will stop whenever the iterator returns false.
func (*LLRB) AscendLessThan ¶
func (t *LLRB) AscendLessThan(pivot Item, iterator ItemIterator)
func (*LLRB) AscendRange ¶
func (t *LLRB) AscendRange(greaterOrEqual, lessThan Item, iterator ItemIterator)
func (*LLRB) Delete ¶
Delete deletes an item from the tree whose key equals key. Returns the deleted item, if any matches, and its position from the smallest item in the tree.
func (*LLRB) DeleteMax ¶
DeleteMax deletes the maximum element in the tree and returns the deleted item or nil otherwise
func (*LLRB) DeleteMin ¶
DeleteMin deletes the minimum element in the tree and returns the deleted item or nil otherwise.
func (*LLRB) DescendLessOrEqual ¶
func (t *LLRB) DescendLessOrEqual(pivot Item, iterator ItemIterator)
DescendLessOrEqual will call iterator once for each element less than the pivot in descending order. It will stop whenever the iterator returns false.
func (*LLRB) GetHeight ¶
GetHeight() returns an item in the tree with key @key, and it's height in the tree
func (*LLRB) Has ¶
Has returns true if the tree contains an element whose order is the same as that of key.
func (*LLRB) HeightStats ¶
HeightStats() returns the average and standard deviation of the height of elements in the tree
func (*LLRB) InsertNoReplace ¶
InsertNoReplace inserts item into the tree. If an existing element has the same order, both elements remain in the tree. Returns the position of the inserted item from the smallest item in the tree.
func (*LLRB) InsertNoReplaceBulk ¶
func (*LLRB) ReplaceOrInsert ¶
ReplaceOrInsert inserts item into the tree. If an existing element has the same order, it is removed from the tree and returned. Returns the replaced item, if any, and the item's position from the smallest item in the tree.