mauricegit / skiplist Goto Github PK
View Code? Open in Web Editor NEWA Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist
License: MIT License
A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist
License: MIT License
I've been trying to find what the behaviour of different methods is with respect to duplicate keys, but can't find anything official or obvious.
Some limited testing has shown that duplicates are added to the list rather than replacing existing entries, but without it written into the specification I'm not sure whether I can rely on this or not. I've also noticed that Find
ing using a key that is duplicated seems to return the SkipListElement at the start of the duplicated block (so you can call Next
to get the next, etc), again not sure I can rely on this behaviour or not.
For the record, I'd like duplicates to continue to be added.
A serialize and deserialize method would be useful in case of save skiplist on file or in a key-value DB
Tried to use the library just now with string keys that should be lexicographically ordered, though noticed that the minimum value returned was incorrect.
Might there be a preferred way to have arbitrary-length string keys in this case? The keys I'm looking to use are 256-bit strings, so this current solution additionally would fail for my use case.
Test case:
package testbed
import (
"github.com/MauriceGit/skiplist"
"math/big"
"testing"
"fmt"
)
type WrappedString struct {
Id string
}
func (w WrappedString) ExtractKey() float64 {
num := new(big.Int)
num.SetBytes([]byte(w.Id))
fmt.Println(w.Id, " ", float64(num.Uint64()))
return float64(num.Uint64())
}
func (w WrappedString) String() string {
return w.Id
}
func TestSkiplist(t *testing.T) {
list := new(skiplist.SkipList)
ids := []string{"a", "b", "c", "d"}
for _, id := range ids {
list.Insert(WrappedString{Id: id})
}
t.Log("min: ", list.GetSmallestNode().GetValue())
t.Log("max: ", list.GetLargestNode().GetValue())
}
Log:
=== RUN TestSkiplist
a 97
b 98
c 99
d 100
--- PASS: TestSkiplist (0.00s)
skiplist_test.go:36: min: b
skiplist_test.go:37: max: d
PASS
ok github.com/iwasaki-kenta/testbed/inmem 0.002s
Hello
This implementation use float64 as key
I have strings like aaaaaaaaaaab
May you please advice how get float64 from this?
go test . -bench=. -run=NOTEST -v -cpuprofile=cpu.out -benchtime=1000000x
goos: darwin
goarch: amd64
pkg: github.com/skiplist
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkSkipListInsert
BenchmarkSkipListInsert-12 1000000 224.7 ns/op
BenchmarkSkipListFind
BenchmarkSkipListFind-12 1000000 151.9 ns/op
BenchmarkSkipListFindBiggerOrEqual
BenchmarkSkipListFindBiggerOrEqual-12 1000000 140.7 ns/op
BenchmarkSkipListDelete
BenchmarkSkipListDelete-12 1000000 72.63 ns/op
go test . -bench=. -run=NOTEST -v -cpuprofile=cpu.out -benchtime=10000000x
goos: darwin
goarch: amd64
pkg: github.com/skiplist
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkSkipListInsert
BenchmarkSkipListInsert-12 10000000 224.0 ns/op
BenchmarkSkipListFind
BenchmarkSkipListFind-12 10000000 163.9 ns/op
BenchmarkSkipListFindBiggerOrEqual
BenchmarkSkipListFindBiggerOrEqual-12 10000000 156.8 ns/op
BenchmarkSkipListDelete
BenchmarkSkipListDelete-12 10000000 80.16 ns/op
go test . -bench=. -run=NOTEST -v -cpuprofile=cpu.out -benchtime=100000000x
goos: darwin
goarch: amd64
pkg: github.com/skiplist
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkSkipListInsert
BenchmarkSkipListInsert-12 100000000 329.4 ns/op
BenchmarkSkipListFind
BenchmarkSkipListFind-12 100000000 369.1 ns/op
BenchmarkSkipListFindBiggerOrEqual
BenchmarkSkipListFindBiggerOrEqual-12 100000000 318.8 ns/op
BenchmarkSkipListDelete
BenchmarkSkipListDelete-12 100000000 269.6 ns/op
Can't provide example right now. Maybe later.
Everything works fine with sean-public/fast-skiplist
hi, i saw the lastest bug you submitted, but i believe that bug still exists, when i test a mutil insert. some of the nodes disappear. I'm trying to solve it
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.