skiplist

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package skiplist provides the implementation for skiplists.

Index

Constants

View Source
const (
	// DefaultMaxLevel is the default max level for a skip list
	DefaultMaxLevel int = 12
	// DefaultProbability is the default probability for deciding levels in a skip list
	DefaultProbability float64 = 0.25
)

Variables

This section is empty.

Functions

func MaxLevelOption

func MaxLevelOption(maxLevel int) order.Option

MaxLevelOption creates an option that sets the max level for a skiplist.

func ProbabilityOption

func ProbabilityOption(p float64) order.Option

ProbabilityOption creates an option that sets the probability for deciding levels in a skiplist.

func RandOption

func RandOption(r *rand.Rand) order.Option

RandOption creates an option that sets the rand source for the skip list.

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a node in a skip list.

func (*Node) Value

func (n *Node) Value() float64

Value returns the value stored at the node.

type SkipList

type SkipList struct {
	// contains filtered or unexported fields
}

SkipList implements a skip list data structure, and also satisfies the order.Statistic interface.

func New

func New(options ...order.Option) (*SkipList, error)

New instantiates a SkipList struct.

func (*SkipList) Add

func (s *SkipList) Add(val float64)

Add inserts a value into the skip list.

func (*SkipList) Clear

func (s *SkipList) Clear()

Clear resets the skip list.

func (*SkipList) Rank

func (s *SkipList) Rank(val float64) int

Rank returns the number of nodes strictly less than the given value.

func (*SkipList) Remove

func (s *SkipList) Remove(val float64)

Remove deletes a value from the skip list.

func (*SkipList) Select

func (s *SkipList) Select(k int) order.Node

Select returns the node with the kth smallest value in the skip list.

func (*SkipList) Size

func (s *SkipList) Size() int

Size returns the size of the skip list.

func (*SkipList) String

func (s *SkipList) String() string

String returns the string representation of the skip list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL