Skip to content
concurrent lock-free skiplist
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitattributes
.gitignore
LICENSE
README.md
errors.go
index.go
iterator.go
node.go
performance.png
performance_test.go
skiplist.go
skiplist_test.go

README.md

concurrent lock-free skiplist

Current Version: 1.0beta

Put, PutOnlyIfAbsent, Update, Get, Contains, Remove, Iterator
//set max level
sl := skiplist.NewSkiplist(32)

key := []byte("test")
val := 123

//put
previou, err := sl.Put(key, unsafe.Pointer(&val)) // return nil, nil

//PutOnlyIfAbsent
previou, err = sl.PutOnlyIfAbsent(key, unsafe.Pointer(&val)) // return nil, key already exists

//update
previou, err = sl.Update(key, func(old unsafe.Pointer) unsafe.Pointer {
	return *(*int)(old)++
}) //return 123, nil

//Get
previou, err = sl.Get(key) //return 124, nil

//Contains
ok, err := sl.Contains(key) //return true, nil

//Remove
previou, err = sl.Remove(key) //return 124, nil

//CompareAndRemove
previou, err = sl.CompareAndRemove(key, value) //return nil, nil

//Get
previou, err = sl.Get(key) //return nil, nil

//Contains
ok, err := sl.Contains(key) //return false, nil

//iterator
it := skiplist.NewIterator(sl, nil, nil)

//Next
for it.Next() {
	key, value := it.NextNode()
}
performance

tested 1000 grounite, each grounite put && get 100000 key-value pairs, result shows follow: image

result shows that put is almost 70% faster than lock map and get is almost 10% faster than lock map

You can’t perform that action at this time.