probabilistic, mutable list-based data structure
Package skiplist
implements a probabilistic, mutable list-based data structure that are a simple and efficient substitute for balanced trees. The algorithm is well depicted by the article.
The library provides generic implementation of
skiplist.Set[K]
ordered set of elementsskiplist.Map[K]
ordered set of key, value pairsskiplist.GF2[K]
finite field on modulo 2
For each of the data type it standardize interfaces around
// Set behavior trait
type Set[K skiplist.Key] interface {
Add(K) bool
Has(K) bool
Cut(K) bool
Values(K) *Element[K]
Successors(K) *Element[K]
Split(K) Set[K]
}
// Map (Key, Value) pairs behavior trait
type Map[K skiplist.Key, V any] interface {
Put(K, V) bool
Get(K) (V, bool)
Cut(K) (V, bool)
Keys(K) *Element[K]
Successors(K) *Element[K]
Split(K) Map[K, V]
}
The latest version of the library is available at main
branch. All development, including new features and bug fixes, take place on the main
branch using forking and pull requests as described in contribution guidelines. The stable version is available via Golang modules.
- Use
go get
to retrieve the library and add it as dependency to your application.
go get github.com/fogfish/skiplist@latest
- Import it in your code
import (
"github.com/fogfish/skiplist"
)
Here is a minimal example on creating an instance of the skiplist.Map
. See the full example
package main
import (
"github.com/fogfish/skiplist"
)
func main() {
kv := skiplist.NewMap[int, string]()
kv.Put(5, "instance")
kv.Get(5)
kv.Cut(5)
}
The library is MIT licensed and accepts contributions via GitHub pull requests:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
The build and testing process requires Go latest version.
Build and run in your development console.
git clone https://github.com/fogfish/skiplist
cd skiplist
go test
go test -run=^$ -bench=. -cpu 1
go test -fuzz=FuzzSetAddCut
go test -fuzz=FuzzMapIntPutGet
go test -fuzz=FuzzMapStringPutGet
go test -fuzz=FuzzGF2
The commit message helps us to write a good release note, speed-up review process. The message should address two question what changed and why. The project follows the template defined by chapter Contributing to a Project of Git book.
If you experience any issues with the library, please let us know via GitHub issues. We appreciate detailed and accurate reports that help us to identity and replicate the issue.