sortlist

package
v0.0.0-...-11d1ae0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 6 Imported by: 0

README

Yet another Concurrent Skiplist in Go

GoDoc Yet another Concurrent Skiplist implementation. Changes are performed using atomic CAS operations. Inserts acquire a shared lock and Writes acquire an exclusive lock. All locking is done internally.

What is a Skip List

Skip List is a data structure that allows fast search within an ordered sequence of elements. Fast search is made possible by maintaining a linked hierarchy of subsequences, each skipping over fewer elements.

image

(from wiki)

Install

go get github.com/byte-mug/golibs/concurrent/sortlist

Usage

package main


import "fmt"
import "github.com/byte-mug/golibs/concurrent/sortlist"
import "github.com/emirpasic/gods/utils"

func main() {
	
	l := &sortlist.Sortlist{Cmp:utils.IntComparator}
	
	l.Insert(10,nil)
	l.Insert(20,nil)
	l.Insert(30,nil)
	
	fmt.Println(l.Previous(5))
	fmt.Println(l.Previous(15))
	fmt.Println(l.Previous(25))
	fmt.Println(l.Previous(35))
	
	fmt.Println("------------------------------------")
	
	fmt.Println(l.Floor(5))
	fmt.Println(l.Floor(15))
	fmt.Println(l.Floor(25))
	fmt.Println(l.Floor(35))
	
	fmt.Println("------------------------------------")
	
	fmt.Println(l.Next(5))
	fmt.Println(l.Next(15))
	fmt.Println(l.Next(25))
	fmt.Println(l.Next(35))
	
	fmt.Println("------------------------------------")
	
	fmt.Println(l.Ceil(5))
	fmt.Println(l.Ceil(15))
	fmt.Println(l.Ceil(25))
	fmt.Println(l.Ceil(35))
	
	fmt.Println("------------------------------------")
	
	fmt.Println(l.Lookup(5))
	fmt.Println(l.Lookup(10))
	fmt.Println(l.Lookup(20))
	fmt.Println(l.Lookup(30))
	
	fmt.Println("------------------------------------")
	
	fmt.Println()
}
Inspired By:

License

This package is licensed under MIT license.

Documentation

Overview

Yet another Concurrent Skiplist implementation. Changes are performed using atomic CAS operations. Inserts acquire a shared lock and Writes acquire an exclusive lock. All locking is done internally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Key   interface{}
	Value interface{}
	// contains filtered or unexported fields
}

func (*Node) Next

func (n *Node) Next() *Node

func (*Node) String

func (n *Node) String() string

type Sortlist

type Sortlist struct {
	Cmp utils.Comparator // Required.
	Src rand.Source      // Optional.
	// contains filtered or unexported fields
}

func (*Sortlist) Ceil

func (s *Sortlist) Ceil(sk interface{}) *Node

func (*Sortlist) Delete

func (s *Sortlist) Delete(k interface{}) *Node

func (*Sortlist) Floor

func (s *Sortlist) Floor(sk interface{}) *Node

func (*Sortlist) Insert

func (s *Sortlist) Insert(k, v interface{})

This function should really be called Put()!

func (*Sortlist) Lookup

func (s *Sortlist) Lookup(sk interface{}) *Node

func (*Sortlist) Next

func (s *Sortlist) Next(sk interface{}) *Node

func (*Sortlist) Previous

func (s *Sortlist) Previous(sk interface{}) *Node

Jump to

Keyboard shortcuts

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