Documentation
¶
Index ¶
- type CompareFunc
- type Iterator
- type K
- type RBTree
- func (tree *RBTree) Clear()
- func (tree *RBTree) Erase(iter Iterator) bool
- func (tree *RBTree) Find(key K) Iterator
- func (tree *RBTree) First() Iterator
- func (tree *RBTree) Format(formatter container.TreeFormatter) string
- func (tree *RBTree) Insert(key K, value V) (Iterator, bool)
- func (tree *RBTree) Last() Iterator
- func (tree RBTree) Len() int
- func (tree *RBTree) MarshalTree(prefix string) string
- func (tree *RBTree) Remove(key K) bool
- func (tree *RBTree) String() string
- type V
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompareFunc ¶
CompareFunc represents comparation between key
type Iterator ¶
type Iterator interface {
// Prev returns previous iterator
Prev() Iterator
// Next returns next node iterator
Next() Iterator
// Key returns key of the node
Key() K
// Value returns value of the node
Value() V
// SetValue sets value of the node
SetValue(V)
// contains filtered or unexported methods
}
Iterator represents an iterator of RBTree to iterate nodes
type RBTree ¶
type RBTree struct {
// contains filtered or unexported fields
}
RBTree RBComment
Example ¶
tree := New(func(k1, k2 K) bool { return k1 > k2 })
fmt.Print("empty:\n" + tree.Format(container.TreeFormatter{}))
tree.Insert(1, 2)
tree.Insert(2, 4)
tree.Insert(4, 8)
tree.Insert(8, 16)
fmt.Print("default:\n" + tree.Format(container.TreeFormatter{}))
fmt.Print("custom:\n" + tree.Format(container.TreeFormatter{
Prefix: "... ",
IconParent: "| ",
IconBranch: "|--",
IconLastBranch: "+--",
}))
fmt.Println("plain:\n" + tree.String())
func (*RBTree) First ¶
First returns the first node.
usage:
iter := tree.First()
for iter != nil {
// hint: do something here using iter
// hint: iter.Key(), iter.Value(), iter.SetValue(newValue)
iter = iter.Next()
}
func (*RBTree) Format ¶
func (tree *RBTree) Format(formatter container.TreeFormatter) string
Format formats the tree
func (*RBTree) Insert ¶
Insert inserts a key-value pair, inserted node and true returned if the key not found, otherwise, existed node and false returned.
func (*RBTree) Last ¶
Last returns the first node.
usage:
iter := tree.Last()
for iter != nil {
// hint: do something here using iter
// hint: iter.Key(), iter.Value(), iter.SetValue(newValue)
iter = iter.Prev()
}
func (*RBTree) MarshalTree ¶
MarshalTree returns a pretty output as a tree
Click to show internal directories.
Click to hide internal directories.