skiplist

package
v1.3.27 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Element

type Element[K, V any] struct {
	Node[K, V]
	// contains filtered or unexported fields
}

Element is a kind of node with key-value data

type Node

type Node[K, V any] struct {
	// contains filtered or unexported fields
}

Node is a list node

type Option

type Option func(option *Options)

Option is a function used to set Options

func WithGoroutineSafe

func WithGoroutineSafe() Option

WithGoroutineSafe sets Skiplist goroutine-safety,

func WithMaxLevel

func WithMaxLevel(maxLevel int) Option

WithMaxLevel sets max level of Skiplist

type Options

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

Options holds Skiplist's options

type Skiplist

type Skiplist[K, V any] struct {
	// contains filtered or unexported fields
}

Skiplist is a kind of data structure which can search quickly by exchanging space for time

func New

func New[K, V any](cmp comparator.Comparator[K], opts ...Option) *Skiplist[K, V]

New news a Skiplist

func (*Skiplist[K, V]) Get

func (sl *Skiplist[K, V]) Get(key K) (V, error)

Get returns the value associated with the passed key if the key is in the skiplist, otherwise returns error

func (*Skiplist[K, V]) Insert

func (sl *Skiplist[K, V]) Insert(key K, value V)

Insert inserts a key-value pair into the skiplist

func (*Skiplist[K, V]) Keys

func (sl *Skiplist[K, V]) Keys() []K

Keys returns all keys in the skiplist

func (*Skiplist[K, V]) Len

func (sl *Skiplist[K, V]) Len() int

Len returns the amount of key-value pair in the skiplist

func (*Skiplist[K, V]) Remove

func (sl *Skiplist[K, V]) Remove(key K) bool

Remove removes the key-value pair associated with the passed key and returns true if the key is in the skiplist, otherwise returns false

func (*Skiplist[K, V]) Traversal

func (sl *Skiplist[K, V]) Traversal(visitor visitor.KvVisitor[K, V])

Traversal traversals elements in the skiplist, it will stop until to the end or the visitor returns false

Jump to

Keyboard shortcuts

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