Documentation ¶
Overview ¶
Package maps 多协程并发安全的TreeMap.
支持多种迭代方式,范围、前缀.
依赖 base/treemap.
Example ¶
package main import ( "fmt" "strconv" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.NewString(-1) for i := 0; i <= 100; i++ { syncMap.Set(strconv.Itoa(i), i) } list := []int{} syncMap.Prefix(func(key string, value int) bool { list = append(list, value) return true }, "1") fmt.Println(list) }
Output: [1 10 100 11 12 13 14 15 16 17 18 19]
Index ¶
- func Group[K constraints.Ordered](key K, num int) int
- type Iterator
- type Maps
- func (p *Maps[K, V]) Add(key K, value V) bool
- func (p *Maps[K, V]) Clear()
- func (p *Maps[K, V]) Del(key K) bool
- func (p *Maps[K, V]) DelMax() bool
- func (p *Maps[K, V]) DelMin() bool
- func (p *Maps[K, V]) Each(iterator Iterator[K, V])
- func (p *Maps[K, V]) EachDesc(iterator Iterator[K, V])
- func (p *Maps[K, V]) Get(key K) (V, bool)
- func (p *Maps[K, V]) GreateOrEqual(iterator Iterator[K, V], greaterOrEqual K)
- func (p *Maps[K, V]) GreateOrEqualDesc(iterator Iterator[K, V], greaterOrEqual K)
- func (p *Maps[K, V]) Len() int
- func (p *Maps[K, V]) LessThan(iterator Iterator[K, V], lessThan K)
- func (p *Maps[K, V]) LessThanDesc(iterator Iterator[K, V], lessThan K)
- func (p *Maps[K, V]) Max() (V, K)
- func (p *Maps[K, V]) Min() (V, K)
- func (p *Maps[K, V]) Range(iterator Iterator[K, V], greaterOrEqual, lessThan K)
- func (p *Maps[K, V]) RangeDesc(iterator Iterator[K, V], greaterOrEqual, lessThan K)
- func (p *Maps[K, V]) Set(key K, value V) bool
- type String
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Iterator ¶
type Iterator[K constraints.Ordered, V any] func(key K, value V) bool
Iterator 迭代器, 返回 false 终止迭代.
type Maps ¶
type Maps[K constraints.Ordered, V any] struct { // contains filtered or unexported fields }
Maps 线程安全的map.
func New ¶
func New[K constraints.Ordered, V any](notFoundKey K, notFoundValue V) *Maps[K, V]
New 新建map,默认分组32个.
func NewByGroup ¶
func NewByGroup[K constraints.Ordered, V any](group int, notFoundKey K, notFoundValue V) *Maps[K, V]
NewByGroup 新建map,自定义分组数量.
func (*Maps[K, V]) Each ¶
Each 遍历.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 10; i++ { syncMap.Set(i, i) } list := []int{} syncMap.Each(func(key, value int) bool { list = append(list, value) return true }) fmt.Println(list) }
Output: [0 1 2 3 4 5 6 7 8 9]
func (*Maps[K, V]) EachDesc ¶
EachDesc 倒叙遍历.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 10; i++ { syncMap.Set(i, i) } list := []int{} syncMap.EachDesc(func(key, value int) bool { list = append(list, value) return true }) fmt.Println(list) }
Output: [9 8 7 6 5 4 3 2 1 0]
func (*Maps[K, V]) GreateOrEqual ¶
GreateOrEqual 大于或等于.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 10; i++ { syncMap.Set(i, i) } list := []int{} syncMap.GreateOrEqual(func(key, value int) bool { list = append(list, value) return true }, 6) fmt.Println(list) }
Output: [6 7 8 9]
func (*Maps[K, V]) GreateOrEqualDesc ¶
GreateOrEqualDesc 倒叙大于等于.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 10; i++ { syncMap.Set(i, i) } list := []int{} syncMap.GreateOrEqualDesc(func(key, value int) bool { list = append(list, value) return true }, 6) fmt.Println(list) }
Output: [9 8 7 6]
func (*Maps[K, V]) LessThan ¶
LessThan 小于.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 10; i++ { syncMap.Set(i, i) } list := []int{} syncMap.LessThan(func(key, value int) bool { list = append(list, value) return true }, 3) fmt.Println(list) }
Output: [0 1 2]
func (*Maps[K, V]) LessThanDesc ¶
LessThanDesc 倒叙小于.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 10; i++ { syncMap.Set(i, i) } list := []int{} syncMap.LessThanDesc(func(key, value int) bool { list = append(list, value) return true }, 3) fmt.Println(list) }
Output: [2 1 0]
func (*Maps[K, V]) Range ¶
Range 范围.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 100; i++ { syncMap.Set(i, i) } list := []int{} syncMap.Range(func(key, value int) bool { list = append(list, value) return true }, 9, 14) fmt.Println(list) }
Output: [9 10 11 12 13]
func (*Maps[K, V]) RangeDesc ¶
RangeDesc 倒叙范围.
Example ¶
package main import ( "fmt" "github.com/xuender/oils/syncs/maps" ) func main() { syncMap := maps.New(-1, -1) for i := 0; i < 100; i++ { syncMap.Set(i, i) } list := []int{} syncMap.RangeDesc(func(key, value int) bool { list = append(list, value) return true }, 9, 14) fmt.Println(list) }
Output: [13 12 11 10 9]
Click to show internal directories.
Click to hide internal directories.