Documentation ¶
Overview ¶
Package rbtree implements operations on Red-Black tree.
Index ¶
- Constants
- type Int
- type Item
- type Iterator
- type Node
- type Rbtree
- func (t *Rbtree) Ascend(pivot Item, iterator Iterator)
- func (t *Rbtree) AscendRange(ge, lt Item, iterator Iterator)
- func (t *Rbtree) Delete(item Item) Item
- func (t *Rbtree) Descend(pivot Item, iterator Iterator)
- func (t *Rbtree) Get(item Item) Item
- func (t *Rbtree) Init() *Rbtree
- func (t *Rbtree) Insert(item Item)
- func (t *Rbtree) InsertOrGet(item Item) Item
- func (t *Rbtree) Len() uint
- func (t *Rbtree) Max() Item
- func (t *Rbtree) Min() Item
- func (t *Rbtree) Search(item Item) *Node
- type String
Constants ¶
const ( // RED represents the color of the node is red RED = 0 // BLACK represents the color of the node is black BLACK = 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
Iterator is the function of iteration entity which would be used by those functions like `Ascend`, `Dscend`, etc.
A typical Iterator with Print :
func loop_with_print(item rbtree.Item) bool { i, ok := item.(XXX) if !ok { return false } fmt.Printf("%+v\n", i) return true }
type Node ¶
Node of the rbtree has a pointer of the node of parent, left, right, also has own color and Item which client uses
type Rbtree ¶
type Rbtree struct { NIL *Node // contains filtered or unexported fields }
Rbtree represents a Red-Black tree.
func (*Rbtree) Ascend ¶
Ascend will call iterator once for each element greater or equal than pivot in ascending order. It will stop whenever the iterator returns false.
func (*Rbtree) AscendRange ¶
AscendRange will call iterator once for elements greater or equal than @ge and less than @lt, which means the range would be [ge, lt). It will stop whenever the iterator returns false.
func (*Rbtree) Descend ¶
Descend will call iterator once for each element less or equal than pivot in descending order. It will stop whenever the iterator returns false.
func (*Rbtree) InsertOrGet ¶
InsertOrGet inserts or retrieves the item in the tree. If the item is already in the tree then the return value will be that. If the item is not in the tree the return value will be the item you put in.