Skip to content

A light, high-performance, concurrent, thread-safe skip list implementation written in Golang.

License

Notifications You must be signed in to change notification settings

AceDarkknight/ConcurrentSkipList

Repository files navigation

ConcurrentSkipList

Build Status Maintainability license Coverage Status Go Report Card

A light, high-performance, concurrent, thread-safe skip list implementation written in Golang.

Getting Start

  • Import package
go get github.com/AceDarkknight/ConcurrentSkipList
import "github.com/AceDarkknight/ConcurrentSkipList"
  • Usage
// Create a new skip list. The parameter is the level of the skip list.
// Parameter must > 0 and <=32, if not, err is not nil.
skipList, err := ConcurrentSkipList.NewConcurrentSkipList(12)
if err != nil {
    fmt.Println(err)
}

// Insert index and value. The index must uint64 and value is interface.
skipList.Insert(uint64(1), 1)
skipList.Insert(uint64(2), 2)

// Search in skip list.
if node, ok := skipList.Search(uint64(1)); ok {
	fmt.Printf("index:%v value:%v\n", node.Index(), node.Value())
}

// Delete by index.
skipList.Delete(uint64(2))

// Get the level of skip list.
_ = skipList.Level()

// Get the length of skip list.
_ = skipList.Length()

// Iterate each node in skip list.
skipList.ForEach(func(node *ConcurrentSkipList.Node) bool {
	fmt.Printf("index:%v value:%v\n", node.Index(), node.Value())
	return true
})

// Select top 10 nodes of skip list.
nodes := skipList.Sub(0, 10)

TODO

  • Reduce memory.
  • Add reverse operation.

References

https://en.wikipedia.org/wiki/Skip_list

About

A light, high-performance, concurrent, thread-safe skip list implementation written in Golang.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages