skiplist

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

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

Element is a kind of node with key-value data

type Node

type Node 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 WithKeyComparator

func WithKeyComparator(cmp comparator.Comparator) Option

WithKeyComparator sets Key comparator option

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 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(opts ...Option) *Skiplist

New news a Skiplist

func (*Skiplist) Get

func (sl *Skiplist) Get(key interface{}) interface{}

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

func (*Skiplist) Insert

func (sl *Skiplist) Insert(key, value interface{})

Insert inserts a key-value pair into the skiplist

func (*Skiplist) Keys

func (sl *Skiplist) Keys() []interface{}

Keys returns all keys in the skiplist

func (*Skiplist) Len

func (sl *Skiplist) Len() int

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

func (*Skiplist) Remove

func (sl *Skiplist) Remove(key interface{}) 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) Traversal

func (sl *Skiplist) Traversal(visitor visitor.KvVisitor)

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