Documentation
¶
Index ¶
- Constants
- type Element
- type Number
- type SkipList
- func (list *SkipList[T]) Front() *Element[T]
- func (list *SkipList[T]) Get(key T) *Element[T]
- func (list *SkipList[T]) Len() int
- func (list *SkipList[T]) Remove(key T) *Element[T]
- func (list *SkipList[T]) Set(key T, value interface{}) *Element[T]
- func (list *SkipList[T]) SetProbability(newProbability float64)
- type Sortable
Constants ¶
const ( // DefaultMaxLevel default height/level of the list // // Suitable for math.Floor(math.Pow(math.E, 18)) == 65659969 elements in list DefaultMaxLevel int = 18 // DefaultProbability default probability of a node could hoist to the higher level DefaultProbability float64 = 1 / math.E )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element[T Sortable] struct { // contains filtered or unexported fields }
func (*Element[T]) Key ¶
func (e *Element[T]) Key() T
Key allows retrieval of the key for a given Element
type Number ¶
type Number interface { int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64 }
Number is a number type
type SkipList ¶
type SkipList[T Sortable] struct { // contains filtered or unexported fields }
func NewWithMaxLevel ¶
NewWithMaxLevel creates a new skip list with MaxLevel set to the provided number. maxLevel has to be int(math.Ceil(math.Log(N))) for DefaultProbability (where N is an upper bound on the number of elements in a skip list). See http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.17.524 Returns a pointer to the new list.
func (*SkipList[T]) Get ¶
Get finds an element by key. It returns element pointer if found, nil if not found. Locking is optimistic and happens only after searching with a fast check for deletion after locking.
func (*SkipList[T]) Remove ¶
Remove deletes an element from the list. Returns removed element pointer if found, nil if not found. Locking is optimistic and happens only after searching with a fast check on adjacent nodes after locking.
func (*SkipList[T]) Set ¶
Set inserts a value in the list with the specified key, ordered by the key. If the key exists, it updates the value in the existing node. Returns a pointer to the new element. Locking is optimistic and happens only after searching.
func (*SkipList[T]) SetProbability ¶
SetProbability changes the current P value of the list. It doesn't alter any existing data, only changes how future insert heights are calculated.