GithubHelp home page GithubHelp logo

mauricegit / skiplist Goto Github PK

View Code? Open in Web Editor NEW
276.0 9.0 38.0 390 KB

A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist

License: MIT License

Go 100.00%
skiplist golang golang-library go data-structures

skiplist's People

Contributors

mauricegit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

skiplist's Issues

Specify behaviour when dealing with duplicate keys

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 Finding 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.

Serialize / Deserialize

A serialize and deserialize method would be useful in case of save skiplist on file or in a key-value DB

Incorrect min. element.

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

Convert string to float

Hello
This implementation use float64 as key
I have strings like aaaaaaaaaaab
May you please advice how get float64 from this?

maybe your test dataset range is too small.

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

relative code

bugs

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.