Documentation ¶
Index ¶
- Constants
- Variables
- type ConcurrentSkipList
- func (c *ConcurrentSkipList[K, T]) Delete(score K)
- func (c *ConcurrentSkipList[K, T]) Draw() *ConcurrentSkipList[K, T]
- func (c *ConcurrentSkipList[K, T]) Get(score K) (elem T, ok bool)
- func (c *ConcurrentSkipList[K, T]) Insert(score K, elem T)
- func (c *ConcurrentSkipList[K, T]) InsertOrUpdate(score K, elem T, cb InsertOrUpdateCb[T])
- func (c *ConcurrentSkipList[K, T]) Len() int
- func (c *ConcurrentSkipList[K, T]) Range(callback func(score K, v T) bool)
- func (c *ConcurrentSkipList[K, T]) RangePrev(callback func(k K, v T) bool) *ConcurrentSkipList[K, T]
- func (c *ConcurrentSkipList[K, T]) Remove(score K) *ConcurrentSkipList[K, T]
- func (c *ConcurrentSkipList[K, T]) Set(score K, elem T)
- func (c *ConcurrentSkipList[K, T]) TopMax(limit int, callback func(k K, v T) bool)
- func (c *ConcurrentSkipList[K, T]) TopMin(limit int, callback func(score K, v T) bool)
- func (c *ConcurrentSkipList[K, T]) TryGet(score K) (elem T, ok bool)
- type InsertOrUpdateCb
- type Node
- type Number
- type SkipList
- func (s *SkipList[K, T]) Delete(score K)
- func (s *SkipList[K, T]) Draw() *SkipList[K, T]
- func (s *SkipList[K, T]) Get(score K) (elem T)
- func (s *SkipList[K, T]) GetWithMeta(score K) (elem T, number Number[K], ok bool)
- func (s *SkipList[K, T]) Insert(score K, elem T)
- func (s *SkipList[K, T]) InsertInner(score K, elem T, level int) (prev T, replaced bool)
- func (s *SkipList[K, T]) InsertOrUpdate(score K, elem T, cb InsertOrUpdateCb[T])
- func (s *SkipList[K, T]) Len() int
- func (s *SkipList[K, T]) Range(callback func(score K, v T) bool)
- func (s *SkipList[K, T]) RangePrev(callback func(k K, v T) bool) *SkipList[K, T]
- func (s *SkipList[K, T]) Remove(score K) *SkipList[K, T]
- func (s *SkipList[K, T]) Set(score K, elem T)
- func (s *SkipList[K, T]) Swap(score K, elem T) (prev T, replaced bool)
- func (s *SkipList[K, T]) TopMax(limit int, callback func(k K, v T) bool)
- func (s *SkipList[K, T]) TopMin(limit int, callback func(score K, v T) bool)
- func (s *SkipList[K, T]) TryGet(score K) (elem T, ok bool)
Constants ¶
const (
SKIPLIST_MAXLEVEL = 32
)
Variables ¶
var (
ErrNotFound = errors.New("not found element")
)
Functions ¶
This section is empty.
Types ¶
type ConcurrentSkipList ¶ added in v0.0.10
type ConcurrentSkipList[K constraints.Ordered, T any] struct { *SkipList[K, T] // contains filtered or unexported fields }
ConcurrentSkipList represents a concurrent-safe skip list It embeds SkipList and adds a RWMutex for thread safety
func NewConcurrent ¶ added in v0.0.10
func NewConcurrent[K constraints.Ordered, T any]() *ConcurrentSkipList[K, T]
NewConcurrent returns a new concurrent-safe skip list
func (*ConcurrentSkipList[K, T]) Delete ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) Delete(score K)
Delete removes an element from the concurrent skip list
func (*ConcurrentSkipList[K, T]) Draw ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) Draw() *ConcurrentSkipList[K, T]
Draw draws the concurrent skip list
func (*ConcurrentSkipList[K, T]) Get ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) Get(score K) (elem T, ok bool)
Get retrieves an element from the concurrent skip list
func (*ConcurrentSkipList[K, T]) Insert ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) Insert(score K, elem T)
Insert inserts a new element into the concurrent skip list
func (*ConcurrentSkipList[K, T]) InsertOrUpdate ¶ added in v0.1.1
func (c *ConcurrentSkipList[K, T]) InsertOrUpdate(score K, elem T, cb InsertOrUpdateCb[T])
Insert or update an element into the concurrent skip list
func (*ConcurrentSkipList[K, T]) Len ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) Len() int
Len returns the length of the concurrent skip list
func (*ConcurrentSkipList[K, T]) Range ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) Range(callback func(score K, v T) bool)
Range iterates over elements in the concurrent skip list
func (*ConcurrentSkipList[K, T]) RangePrev ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) RangePrev(callback func(k K, v T) bool) *ConcurrentSkipList[K, T]
RangePrev iterates over elements in the concurrent skip list in reverse order
func (*ConcurrentSkipList[K, T]) Remove ¶ added in v0.1.1
func (c *ConcurrentSkipList[K, T]) Remove(score K) *ConcurrentSkipList[K, T]
Remove removes an element from the concurrent skip list
func (*ConcurrentSkipList[K, T]) Set ¶ added in v0.1.1
func (c *ConcurrentSkipList[K, T]) Set(score K, elem T)
Set sets a new element into the concurrent skip list
func (*ConcurrentSkipList[K, T]) TopMax ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) TopMax(limit int, callback func(k K, v T) bool)
TopMax returns the top max elements from the concurrent skip list
func (*ConcurrentSkipList[K, T]) TopMin ¶ added in v0.0.10
func (c *ConcurrentSkipList[K, T]) TopMin(limit int, callback func(score K, v T) bool)
TopMin returns the top min elements from the concurrent skip list
func (*ConcurrentSkipList[K, T]) TryGet ¶ added in v0.1.1
func (c *ConcurrentSkipList[K, T]) TryGet(score K) (elem T, ok bool)
TryGet retrieves an element from the concurrent skip list
type InsertOrUpdateCb ¶ added in v0.1.1
type InsertOrUpdateCb[T any] func(prev T, new T) T
type Node ¶
type Node[K constraints.Ordered, T any] struct { NodeLevel []struct { // contains filtered or unexported fields } // contains filtered or unexported fields }
type Number ¶
type Number[K constraints.Ordered] struct { Total int Keys []K Level []int MaxLevel []int }
debug 使用
type SkipList ¶
type SkipList[K constraints.Ordered, T any] struct { // contains filtered or unexported fields }
func New ¶
func New[K constraints.Ordered, T any]() *SkipList[K, T]
初始化skiplist func New[T any](compare func(T, T) int) *SkipList[T] {
func (*SkipList[K, T]) GetWithMeta ¶
debug使用, 返回查找某个key 比较的次数+经过的节点数
func (*SkipList[K, T]) InsertInner ¶
方便给作者调试用的函数
func (*SkipList[K, T]) InsertOrUpdate ¶ added in v0.1.1
func (s *SkipList[K, T]) InsertOrUpdate(score K, elem T, cb InsertOrUpdateCb[T])
Insert or update an element into the skip list