Documentation
¶
Overview ¶
Package treemap 左倾红黑树 Map.
left-leaning red-black tree map.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/base/treemap" ) func main() { tmap := treemap.New(-1, -1) for i := 0; i < 10; i++ { tmap.Set(i, i) } for i := 3; i < 8; i++ { tmap.Del(i) } tmap.Each(func(key, value int) bool { fmt.Println(value) return true }) }
Output: 0 1 2 8 9
Index ¶
- func PrefixNext(prefix string) string
- type Iterator
- type String
- type TreeMap
- func (p *TreeMap[K, V]) Add(key K, value V) bool
- func (p *TreeMap[K, V]) Clear()
- func (p *TreeMap[K, V]) Del(key K) bool
- func (p *TreeMap[K, V]) DelMax() bool
- func (p *TreeMap[K, V]) DelMin() bool
- func (p *TreeMap[K, V]) Each(iterator Iterator[K, V])
- func (p *TreeMap[K, V]) EachDesc(iterator Iterator[K, V])
- func (p *TreeMap[K, V]) Get(key K) (V, bool)
- func (p *TreeMap[K, V]) GreateOrEqual(iterator Iterator[K, V], greaterOrEqual K)
- func (p *TreeMap[K, V]) GreateOrEqualDesc(iterator Iterator[K, V], greaterOrEqual K)
- func (p *TreeMap[K, V]) Len() int
- func (p *TreeMap[K, V]) LessThan(iterator Iterator[K, V], lessThan K)
- func (p *TreeMap[K, V]) LessThanDesc(iterator Iterator[K, V], lessThan K)
- func (p *TreeMap[K, V]) Max() (V, K)
- func (p *TreeMap[K, V]) Min() (V, K)
- func (p *TreeMap[K, V]) Range(iterator Iterator[K, V], greaterOrEqual, lessThan K)
- func (p *TreeMap[K, V]) RangeDesc(iterator Iterator[K, V], greaterOrEqual, lessThan K)
- func (p *TreeMap[K, V]) Set(key K, value V) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Iterator ¶ added in v0.5.40
type Iterator[K constraints.Ordered, V any] func(key K, value V) bool
Iterator 迭代器,返回 false 终止迭代..
type String ¶ added in v0.4.39
String 键值 string.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/base/treemap" ) func main() { tmap := treemap.NewString(-1) for i := 100; i < 200; i++ { tmap.Set(fmt.Sprintf("a%d", i), i) } for i := 0; i < 10; i++ { tmap.Set(fmt.Sprintf("b%d", i), i) } list := []int{} tmap.Prefix(func(key string, value int) bool { list = append(list, value) return true }, "b") fmt.Println(list) }
Output: [0 1 2 3 4 5 6 7 8 9]
type TreeMap ¶
type TreeMap[K constraints.Ordered, V any] struct { // contains filtered or unexported fields }
TreeMap 左倾红黑树Map. left-leaning red-black tree map.
func New ¶
func New[K constraints.Ordered, V any](noFoundKey K, notFoundValue V) *TreeMap[K, V]
New 新建 TreeMap. notFound 找不到时返回的值.
func (*TreeMap[K, V]) Each ¶
Each 遍历.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/base/treemap" ) func main() { llrb := treemap.New(-1, -1) for i := 0; i < 5; i++ { llrb.Set(i, i) } llrb.Each(func(key, value int) bool { fmt.Println(key, value) return true }) }
Output: 0 0 1 1 2 2 3 3 4 4
func (*TreeMap[K, V]) GreateOrEqual ¶
GreateOrEqual 大于等于.
func (*TreeMap[K, V]) GreateOrEqualDesc ¶
GreateOrEqualDesc 倒叙大于等于.
func (*TreeMap[K, V]) LessThanDesc ¶
LessThanDesc 倒叙小于.
Click to show internal directories.
Click to hide internal directories.