Documentation
¶
Overview ¶
Package skiplist implements a probabilistic list-based data structure that are a simple and efficient substitute for balanced trees.
Please see the article that depicts the data structure https://15721.courses.cs.cmu.edu/spring2018/papers/08-oltpindexes1/pugh-skiplists-cacm1990.pdf http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.17.524
Index ¶
- Constants
- func ForGF2[K Num](gf2 *GF2[K], key *Element[K]) pair.Seq[K, Arc[K]]
- func ForHashMap[K Key, V any](kv *HashMap[K, V], key *Element[K]) pair.Seq[K, V]
- func ForMap[K Key, V any](kv *Map[K, V], el *Pair[K, V]) pair.Seq[K, V]
- func ForSet[K Key](set *Set[K], el *Element[K]) seq.Seq[K]
- type Allocator
- type Arc
- type Element
- type GF2
- type HashMap
- func (kv *HashMap[K, V]) Cut(key K) (V, bool)
- func (kv *HashMap[K, V]) Get(key K) (V, bool)
- func (kv *HashMap[K, V]) Keys() *Element[K]
- func (kv *HashMap[K, V]) Length() int
- func (kv *HashMap[K, V]) Level() int
- func (kv *HashMap[K, V]) Put(key K, val V) (bool, *Element[K])
- func (kv *HashMap[K, V]) Skip(level int, key K) (*Element[K], [L]*Element[K])
- func (kv *HashMap[K, V]) Split(key K) *HashMap[K, V]
- func (kv *HashMap[K, V]) String() string
- func (kv *HashMap[K, V]) Successor(key K) *Element[K]
- type Key
- type Map
- func (kv *Map[K, V]) CreatePair(maxL int, key K, val V) (int, *Pair[K, V])
- func (kv *Map[K, V]) Cut(key K) (bool, *Pair[K, V])
- func (kv *Map[K, V]) Get(key K) (V, *Pair[K, V])
- func (kv *Map[K, V]) Head() *Pair[K, V]
- func (kv *Map[K, V]) Length() int
- func (kv *Map[K, V]) Level() int
- func (kv *Map[K, V]) NewPair(key K, rank int) *Pair[K, V]
- func (kv *Map[K, V]) Put(key K, val V) (bool, *Pair[K, V])
- func (kv *Map[K, V]) Skip(level int, key K) (*Pair[K, V], [L]*Pair[K, V])
- func (kv *Map[K, V]) Split(key K) *Map[K, V]
- func (kv *Map[K, V]) String() string
- func (kv *Map[K, V]) Successor(key K) *Pair[K, V]
- func (kv *Map[K, V]) Values() *Pair[K, V]
- type MapConfig
- type Num
- type Pair
- type Set
- func (set *Set[K]) Add(key K) (bool, *Element[K])
- func (set *Set[K]) CreateElement(maxL int, key K) (int, *Element[K])
- func (set *Set[K]) Cut(key K) (bool, *Element[K])
- func (set *Set[K]) Has(key K) (bool, *Element[K])
- func (set *Set[K]) Head() *Element[K]
- func (set *Set[K]) Length() int
- func (set *Set[K]) Level() int
- func (set *Set[K]) NewElement(key K, rank int) *Element[K]
- func (set *Set[K]) Skip(level int, key K) (*Element[K], [L]*Element[K])
- func (set *Set[K]) Split(key K) *Set[K]
- func (set *Set[K]) String() string
- func (set *Set[K]) Successor(key K) *Element[K]
- func (set *Set[K]) Values() *Element[K]
- type SetConfig
Constants ¶
const L = 22
L depth of fingers at each node.
The value is estimated as math.Log10(float64(n)) / math.Log10(1/p) n = 4294967296, p = 1/math.E
Variables ¶
This section is empty.
Functions ¶
func ForHashMap ¶ added in v0.15.0
Types ¶
type Element ¶ added in v0.11.0
Each element is represented by a Element in a skip structures. Each node has a height or level (length of fingers array), which corresponds to the number of forward pointers the node has. When a new element is inserted into the list, a node with a random level is inserted to represent the element. Random levels are generated with a simple pattern: 50% are level 1, 25% are level 2, 12.5% are level 3 and so on.
func (*Element[K]) Next ¶ added in v0.11.0
Return next element in the set. Use for-loop to iterate through set elements
for e := set.Successor(...); e != nil; e.Next() { /* ... */}
type GF2 ¶ added in v0.11.0
type GF2[K Num] struct { // contains filtered or unexported fields }
type HashMap ¶ added in v0.15.0
func NewHashMap ¶ added in v0.15.0
type Key ¶ added in v0.11.0
type Key interface { ~string | ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 }
Constraint on key types supported by the data structures
type Map ¶ added in v0.11.0
Map of Elements
func (*Map[K, V]) CreatePair ¶ added in v0.15.0
creates a new node, randomly defines empty fingers (level of the node)
func (*Map[K, V]) Cut ¶ added in v0.11.0
Cut element from the set, returns true if element is removed
func (*Map[K, V]) Skip ¶ added in v0.15.0
skip algorithm is similar to search algorithm that traversing forward pointers. skip maintain the vector path that contains a pointer to the rightmost node of level i or higher that is to the left of the location of the insertion/deletion.
type MapConfig ¶ added in v0.15.0
Configure Set properties
func MapWithAllocator ¶ added in v0.15.0
Configure Memory Allocator
func MapWithBlockSize ¶ added in v0.15.0
Configure Probability table so that each level takes (√B)ⁿ elements
func MapWithProbability ¶ added in v0.15.0
Configure Probability table Use math.Log(B)/B < p < math.Pow(B, -0.5)
The probability help to control the "distance" between elements on each level Use p = math.Pow(B, -0.5), where B is number of elements On L1 distance is √B, L2 distance is B, Ln distance is (√B)ⁿ
type Pair ¶ added in v0.15.0
Each key-value pair is represented by a Pair in a skip structures. Each node has a height or level (length of fingers array), which corresponds to the number of forward pointers the node has. When a new element is inserted into the list, a node with a random level is inserted to represent the element. Random levels are generated with a simple pattern: 50% are level 1, 25% are level 2, 12.5% are level 3 and so on.
func (*Pair[K, V]) Next ¶ added in v0.15.0
Return next element in the set. Use for-loop to iterate through set elements
for e := set.Successor(...); e != nil; e.Next() { /* ... */}
type Set ¶ added in v0.11.0
type Set[K Key] struct { // contains filtered or unexported fields }
Set of Elements
func (*Set[K]) CreateElement ¶ added in v0.15.0
mkNode creates a new node, randomly defines empty fingers (level of the node)
func (*Set[K]) NewElement ¶ added in v0.15.0
allocate new node
func (*Set[K]) Skip ¶ added in v0.15.0
skip algorithm is similar to search algorithm that traversing forward pointers. skip maintain the vector path that contains a pointer to the rightmost node of level i or higher that is to the left of the location of the insertion/deletion.
type SetConfig ¶ added in v0.15.0
Configure Set properties
func SetWithAllocator ¶ added in v0.15.0
Configure Memory Allocator
func SetWithBlockSize ¶ added in v0.15.0
Configure Probability table so that each level takes (√B)ⁿ elements
func SetWithProbability ¶ added in v0.15.0
Configure Probability table Use math.Log(B)/B < p < math.Pow(B, -0.5)
The probability help to control the "distance" between elements on each level Use p = math.Pow(B, -0.5), where B is number of elements On L1 distance is √B, L2 distance is B, Ln distance is (√B)ⁿ