Documentation
¶
Overview ¶
Example ¶
l := New(func(a, b int) bool {
return a < b
})
for _, v := range []int{10, 12, 15} {
if l.Store(v) {
fmt.Println("skipset add", v)
}
}
if l.Contains(10) {
fmt.Println("skipset contains 10")
}
l.Range(func(value int) bool {
fmt.Println("skipset range found ", value)
return true
})
l.Remove(15)
fmt.Printf("skipset contains %d items\r\n", l.Len())
Index ¶
- type SkipSet
- func (s *SkipSet[T]) AscendGreaterEqual(value T, f func(value T) bool)
- func (s *SkipSet[T]) Contains(value T) bool
- func (s *SkipSet[T]) Len() int
- func (s *SkipSet[T]) Load(value T) (v T, found bool)
- func (s *SkipSet[T]) LoadOrStore(value T, newValue ValueOrFuncValue[T]) (actual T, loaded bool)
- func (s *SkipSet[T]) Max() T
- func (s *SkipSet[T]) Min() T
- func (s *SkipSet[T]) Range(f func(value T) bool)
- func (s *SkipSet[T]) Remove(value T) bool
- func (s *SkipSet[T]) Set(value T)
- func (s *SkipSet[T]) Store(value T) bool
- type ValueOrFuncValue
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SkipSet ¶
type SkipSet[T any] struct { // contains filtered or unexported fields }
SkipSet represents a generic set based on skip list
func (*SkipSet[T]) AscendGreaterEqual ¶
AscendGreaterEqual calls f sequentially for each value present in the set greater than or equal to value. If f returns false, range stops the iteration.
func (*SkipSet[T]) LoadOrStore ¶ added in v0.13.0
func (s *SkipSet[T]) LoadOrStore(value T, newValue ValueOrFuncValue[T]) (actual T, loaded bool)
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*SkipSet[T]) Max ¶ added in v0.17.0
func (s *SkipSet[T]) Max() T
Max returns the maximum value in the set. If it is empty then the zero value is returned.
func (*SkipSet[T]) Min ¶ added in v0.17.0
func (s *SkipSet[T]) Min() T
Min returns the minimum value in the set. If it is empty then the zero value is returned.
func (*SkipSet[T]) Range ¶
Range calls f sequentially for each value present in the set. If f returns false, range stops the iteration.
func (*SkipSet[T]) Set ¶ added in v0.16.0
func (s *SkipSet[T]) Set(value T)
Set is similar to store but ensures given value is stored into the set.
func (*SkipSet[T]) Store ¶ added in v0.13.0
Store adds the value into the set, return true if this process insert the value into the set, return false if this process can't insert this value, because another process has inserted the same value.
If the value is in the set but not fully linked, this process will wait until it is.