Documentation ¶
Index ¶
- Variables
- func NoescapeInterface(x interface{}) interface{}
- type Map
- func (s *Map) Begin() MapNode
- func (s *Map) Count(key interface{}) (count int)
- func (t *Map) Empty() bool
- func (s *Map) End() MapNode
- func (s *Map) EqualRange(key interface{}) (beg, end MapNode)
- func (s *Map) Erase(key interface{}) (count int)
- func (s *Map) EraseNode(n MapNode)
- func (s *Map) EraseNodeRange(beg, end MapNode) (count int)
- func (s *Map) Find(key interface{}) MapNode
- func (t *Map) GetMaxSpan() uint32
- func (s *Map) Init(unique bool, key, val interface{}, compare func(a, b interface{}) int)
- func (s *Map) Insert(key interface{}, val interface{}) (MapNode, bool)
- func (s *Map) LowerBound(key interface{}) MapNode
- func (t *Map) SetMaxSpan(maxSpan uint32)
- func (t *Map) Size() int
- func (t *Map) Unique() bool
- func (s *Map) UpperBound(key interface{}) MapNode
- type MapNode
- type Set
- func (s *Set) Begin() SetNode
- func (s *Set) Count(data interface{}) (count int)
- func (t *Set) Empty() bool
- func (s *Set) End() SetNode
- func (s *Set) EqualRange(data interface{}) (beg, end SetNode)
- func (s *Set) Erase(data interface{}) (count int)
- func (s *Set) EraseNode(n SetNode)
- func (s *Set) EraseNodeRange(beg, end SetNode) (count int)
- func (s *Set) Find(data interface{}) SetNode
- func (t *Set) GetMaxSpan() uint32
- func (s *Set) Init(unique bool, data interface{}, compare func(a, b interface{}) int)
- func (s *Set) Insert(data interface{}) (SetNode, bool)
- func (s *Set) LowerBound(data interface{}) SetNode
- func (t *Set) SetMaxSpan(maxSpan uint32)
- func (t *Set) Size() int
- func (t *Set) Unique() bool
- func (s *Set) UpperBound(data interface{}) SetNode
- type SetNode
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotInTree = errors.New("node is not a node of this tree") ErrNoLast = errors.New("begin of tree has no Last()") ErrNoNext = errors.New("end of tree has no Next()") ErrEraseEmpty = errors.New("can't erase empty node") ErrNoData = errors.New("tree has no data") ErrNoValue = errors.New("tree has no value") ErrBadKey = errors.New("not same key type with tree") ErrBadValue = errors.New("not same value type with tree") )
Functions ¶
func NoescapeInterface ¶
func NoescapeInterface(x interface{}) interface{}
you can use this func to make the arguments of insert method don't escape to heap if it's not direct interface{} (make sure this)! you can find a example in file example_test.go. USE CAREFULLY!
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "fmt" "github.com/cdongyang/rbtree" ) func main() { var slice = []int{1, 4, 6, 5, 3, 7, 2, 9} // key type: int, value type: *int mp := rbtree.NewMap(int(0), new(int), func(a, b interface{}) int { return a.(int) - b.(int) }) for i := range slice { mp.Insert(slice[i], &slice[i]) } var indexOf = func(p *int) int { for i := range slice { if &slice[i] == p { return i } } return -1 } // iterator for it, i := mp.Begin(), 0; it != mp.End(); it = it.Next() { fmt.Println(it.GetKey(), indexOf(it.GetVal().(*int))) i++ } mp = nil // free tree to make it collect by GC }
Output: 1 0 2 6 3 4 4 1 5 3 6 2 7 5 9 7
func NewMultiMap ¶
func (*Map) EqualRange ¶
func (*Map) EraseNodeRange ¶
func (*Map) GetMaxSpan ¶
func (t *Map) GetMaxSpan() uint32
func (*Map) LowerBound ¶
func (*Map) SetMaxSpan ¶
func (t *Map) SetMaxSpan(maxSpan uint32)
func (*Map) UpperBound ¶
type MapNode ¶
type MapNode struct {
// contains filtered or unexported fields
}
MapNode is the iterator of Map, but it's not thread safe, if the node was erase from map, calling it's method may panic
func (MapNode) GetKey ¶
func (n MapNode) GetKey() interface{}
GetKey get the key of MapNode, but you should not hold the return interface{}, instead, you should do type assert immediately when after call this method
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
func NewMultiSet ¶
NewSet return a not unique set with data type and compare func, the return set has been executed init func.
func NewSet ¶
NewSet return a unique set with data type and compare func, the return set has been executed init func.
func (*Set) EqualRange ¶
func (*Set) EraseNode ¶
EraseNode erase a SetNode from tree, if SetNode has been erased, calling will panic
func (*Set) EraseNodeRange ¶
func (*Set) GetMaxSpan ¶
func (t *Set) GetMaxSpan() uint32
func (*Set) Init ¶
Init init the set, function NewSet and NewMultiSet will calle it, only the first call of this function will have an affect on set
func (*Set) LowerBound ¶
func (*Set) SetMaxSpan ¶
func (t *Set) SetMaxSpan(maxSpan uint32)
func (*Set) UpperBound ¶
type SetNode ¶
type SetNode struct {
// contains filtered or unexported fields
}
SetNode is the iterator of set, but it's not thread safe, if the node was erase from set, calling it's method may panic
func (SetNode) GetData ¶
func (n SetNode) GetData() interface{}
GetData get the data of SetNode, but you should not hold the return interface{}, instead, you should do type assert immediately when after call this method