Documentation ¶
Index ¶
Constants ¶
const ( // Suitable for math.Floor(math.Pow(math.E, 18)) == 65659969 elements in list DefaultMaxLevel int = 18 DefaultProbability float64 = 1 / math.E )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
type SkipList ¶
type SkipList struct { Length int // contains filtered or unexported fields }
func New ¶
func New() *SkipList
New creates a new skip list with default parameters. Returns a pointer to the new list.
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) 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) 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) 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) 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.