skiplist

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package skiplist implements a skiplist. See https://en.wikipedia.org/wiki/Skip_list for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

Node represents node of a list.

func (*Node[T]) Below

func (n *Node[T]) Below() *Node[T]

Below returns Node below.

func (*Node[T]) HasBelow

func (n *Node[T]) HasBelow() bool

HasBelow returns true if node below exist.

func (*Node[T]) HasNext

func (n *Node[T]) HasNext() bool

HasNext returns true if next node exist.

func (*Node[T]) Next

func (n *Node[T]) Next() *Node[T]

Next returns next Node.

func (*Node[T]) Value

func (n *Node[T]) Value() T

Value return value in Node.

type SkipList

type SkipList[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

SkipList represents a skiplist. Zero value of SkipList is invalid skiplist, should be used only with New() or NewWithProbability().

func New

func New[T constraints.Ordered]() *SkipList[T]

New returns an initialized skiplist with probability = 0.5.

func NewWithProbability

func NewWithProbability[T constraints.Ordered](p float64) *SkipList[T]

NewWithProbability returns an initialized skiplist with given probability.

func (*SkipList[T]) All

func (s *SkipList[T]) All() []T

All returns all elements from the skiplist.

func (*SkipList[T]) Contains

func (s *SkipList[T]) Contains(value T) bool

Contains returns true if skiplist contains given value, false otherwise.

func (*SkipList[T]) Find

func (s *SkipList[T]) Find(value T) *Node[T]

Find returns Node that contains value if its exist, closest otherwise.

func (*SkipList[T]) Insert

func (s *SkipList[T]) Insert(value T)

Insert inserts value in a skiplist.

func (*SkipList[T]) Remove

func (s *SkipList[T]) Remove(value T) bool

Remove removes value from skiplist. Returns true if skiplist contained given value, false otherwise.

Jump to

Keyboard shortcuts

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