Documentation
¶
Index ¶
- Constants
- type Element
- type SkipList
- func (list *SkipList) CompactList(timeNow, maxWait int64) ([]SkippedSequenceEntry, int64, int64)
- func (list *SkipList) Front() *Element
- func (list *SkipList) Get(key SkippedSequenceEntry) *Element
- func (list *SkipList) GetLastElement() *Element
- func (list *SkipList) GetLength() int
- func (list *SkipList) GetNumSequencesInList() int64
- func (list *SkipList) Remove(key SkippedSequenceEntry) (*Element, int64, error)
- func (list *SkipList) Set(key SkippedSequenceEntry) (*Element, error)
- func (list *SkipList) SetProbability(newProbability float64)
- type SkippedSequenceEntry
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
}
func (*Element) IsWithinRange ¶
func (element *Element) IsWithinRange(elem SkippedSequenceEntry) bool
IsWithinRange checks if the SkippedSequenceEntry is within the range of the Element's key.
func (*Element) Key ¶
func (e *Element) Key() SkippedSequenceEntry
Key allows retrieval of the key for a given Element
type SkipList ¶
type SkipList struct {
NumSequencesInList int64
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) CompactList ¶
func (list *SkipList) CompactList(timeNow, maxWait int64) ([]SkippedSequenceEntry, int64, int64)
CompactList compacts the skiplist by removing elements that are older than maxWait. Returns number of sequences compacted and number of sequences left in list
func (*SkipList) Get ¶
func (list *SkipList) Get(key SkippedSequenceEntry) *Element
Get finds an element by key. It returns element pointer if found, nil if not found.
func (*SkipList) GetLastElement ¶
GetLastElement will return the last element in the skiplist
func (*SkipList) GetNumSequencesInList ¶
GetNumSequencesInList will return the total number of sequences in the skiplist
func (*SkipList) Remove ¶
func (list *SkipList) Remove(key SkippedSequenceEntry) (*Element, int64, error)
Remove deletes an element from the list. Returns removed element pointer if found, nil if not found. Also returns the number of sequences left in list and an error if the element was not found.
func (*SkipList) Set ¶
func (list *SkipList) Set(key SkippedSequenceEntry) (*Element, error)
Set inserts a value in the list with the specified key, ordered by the key. If the key exists, we will error, this is unexpected behaviour Returns a pointer to the new element nd error type.
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.
type SkippedSequenceEntry ¶
func (*SkippedSequenceEntry) GetNumSequencesInEntry ¶
func (s *SkippedSequenceEntry) GetNumSequencesInEntry() int64
GetNumSequencesInEntry return the number of sequences in the SkippedSequenceEntry sequence range.
func (*SkippedSequenceEntry) String ¶
func (s *SkippedSequenceEntry) String() string
String will return a string representation of the SkippedSequenceEntry Formats: Singular: "#<seq>" or ranges: "#<start>-#<end>"