Documentation ¶
Index ¶
- Variables
- type Comparator
- type Iterator
- type Skiplist
- func (l *Skiplist[K, V]) Contains(key K) bool
- func (l *Skiplist[K, V]) Get(key K) (ret V, found bool)
- func (l *Skiplist[K, V]) Height() int
- func (l *Skiplist[K, V]) Insert(key K, value V)
- func (l *Skiplist[K, V]) LessOrEqual(key K) (retk K, retv V, found bool)
- func (l *Skiplist[K, V]) Remove(key K) bool
- func (l *Skiplist[K, V]) Scan() *Iterator[K, V]
- func (l *Skiplist[K, V]) ScanFrom(key K) *Iterator[K, V]
- func (l *Skiplist[K, V]) ScanRange(start, end K) *Iterator[K, V]
- func (l *Skiplist[K, V]) Size() int
Constants ¶
This section is empty.
Variables ¶
var ( IntComparator = orderedComparator[int] Int8Comparator = orderedComparator[int8] Int16Comparator = orderedComparator[int16] Int32Comparator = orderedComparator[int32] Int64Comparator = orderedComparator[int64] UintComparator = orderedComparator[uint] Uint8Comparator = orderedComparator[uint8] Uint16Comparator = orderedComparator[uint16] Uint32Comparator = orderedComparator[uint32] Uint64Comparator = orderedComparator[uint64] Float32Comparator = orderedComparator[float32] Float64Comparator = orderedComparator[float64] StringComparator = orderedComparator[string] )
Functions ¶
This section is empty.
Types ¶
type Comparator ¶
Comparator is a function that compares two keys. It returns a negative number if a < b, 0 if a == b, and a positive number if a > b.
func InverseComparator ¶
func InverseComparator[T constraints.Ordered](comparator Comparator[T]) Comparator[T]
type Iterator ¶
Iterator is an iterator over a Skiplist.
type Skiplist ¶
Skiplist is a generic skiplist implementation. It is thread safe and supports concurrent reads and writes. It allows to multiple readers to access the list simultaneously, but only a single writer. The writer does not block the readers, and the readers do not block the writer.
func New ¶
func New[K any, V any](comparator Comparator[K]) *Skiplist[K, V]
New returns a new Skiplist. The comparator is used to compare keys.
func (*Skiplist[K, V]) Get ¶
Get returns the value for the given key. If the key is not found, ErrNotFound is returned.
func (*Skiplist[K, V]) Insert ¶
func (l *Skiplist[K, V]) Insert(key K, value V)
Insert inserts a new key-value pair into the list.
func (*Skiplist[K, V]) LessOrEqual ¶
LessOrEqual returns the value for the key that is less than the given key.
func (*Skiplist[K, V]) Remove ¶
Remove removes the key-value pair with the given key from the list. It returns true if the key was found.
func (*Skiplist[K, V]) Scan ¶
Scan returns an iterator that scans the list from the beginning. Note that the list may change while the iterator is in use.
func (*Skiplist[K, V]) ScanFrom ¶
ScanFrom returns an iterator that scans the list from the given key. Note that the list may change while the iterator is in use.