Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryszard/goskiplist
A skip list implementation in Go
https://github.com/ryszard/goskiplist
Last synced: 4 days ago
JSON representation
A skip list implementation in Go
- Host: GitHub
- URL: https://github.com/ryszard/goskiplist
- Owner: ryszard
- License: apache-2.0
- Created: 2012-05-09T05:44:59.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2019-10-29T10:07:30.000Z (about 5 years ago)
- Last Synced: 2024-10-25T04:09:50.389Z (11 days ago)
- Language: Go
- Size: 194 KB
- Stars: 240
- Watchers: 16
- Forks: 60
- Open Issues: 6
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
- awesome-go - goskiplist - A skip list implementation in Go - ★ 172 (Data Structures)
README
About
=====This is a library implementing skip lists for the Go programming
language (http://golang.org/).Skip lists are a data structure that can be used in place of
balanced trees. Skip lists use probabilistic balancing rather than
strictly enforced balancing and as a result the algorithms for
insertion and deletion in skip lists are much simpler and
significantly faster than equivalent algorithms for balanced trees.Skip lists were first described in
[Pugh, William (June 1990)](ftp://ftp.cs.umd.edu/pub/skipLists/skiplists.pdf). "Skip
lists: a probabilistic alternative to balanced trees". Communications
of the ACM 33 (6): 668–676[![Build Status](https://travis-ci.org/ryszard/goskiplist.png?branch=master)](https://travis-ci.org/ryszard/goskiplist)
Installing
==========$ go get github.com/ryszard/goskiplist/skiplist
Example
=======```go
package mainimport (
"fmt"
"github.com/ryszard/goskiplist/skiplist"
)func main() {
s := skiplist.NewIntMap()
s.Set(7, "seven")
s.Set(1, "one")
s.Set(0, "zero")
s.Set(5, "five")
s.Set(9, "nine")
s.Set(10, "ten")
s.Set(3, "three")firstValue, ok := s.Get(0)
if ok {
fmt.Println(firstValue)
}
// prints:
// zeros.Delete(7)
secondValue, ok := s.Get(7)
if ok {
fmt.Println(secondValue)
}
// prints: nothing.s.Set(9, "niner")
// Iterate through all the elements, in order.
unboundIterator := s.Iterator()
for unboundIterator.Next() {
fmt.Printf("%d: %s\n", unboundIterator.Key(), unboundIterator.Value())
}
// prints:
// 0: zero
// 1: one
// 3: three
// 5: five
// 9: niner
// 10: tenfor unboundIterator.Previous() {
fmt.Printf("%d: %s\n", unboundIterator.Key(), unboundIterator.Value())
}
// 9: niner
// 5: five
// 3: three
// 1: one
// 0: zeroboundIterator := s.Range(3, 10)
// Iterate only through elements in some range.
for boundIterator.Next() {
fmt.Printf("%d: %s\n", boundIterator.Key(), boundIterator.Value())
}
// prints:
// 3: three
// 5: five
// 9: ninerfor boundIterator.Previous() {
fmt.Printf("%d: %s\n", boundIterator.Key(), boundIterator.Value())
}
// prints:
// 5: five
// 3: threevar iterator skiplist.Iterator
iterator = s.Seek(3)
fmt.Printf("%d: %s\n", iterator.Key(), iterator.Value())
// prints:
// 3: threeiterator = s.Seek(2)
fmt.Printf("%d: %s\n", iterator.Key(), iterator.Value())
// prints:
// 3: threeiterator = s.SeekToFirst()
fmt.Printf("%d: %s\n", iterator.Key(), iterator.Value())
// prints:
// 0: zeroiterator = s.SeekToLast()
fmt.Printf("%d: %s\n", iterator.Key(), iterator.Value())
// prints:
// 10: ten// SkipList can also reduce subsequent forward seeking costs by reusing the
// same iterator:iterator = s.Seek(3)
fmt.Printf("%d: %s\n", iterator.Key(), iterator.Value())
// prints:
// 3: threeiterator.Seek(5)
fmt.Printf("%d: %s\n", iterator.Key(), iterator.Value())
// prints:
// 5: five
}
```Full documentation
==================Read it [online](http://godoc.org/github.com/ryszard/goskiplist/skiplist) or run
$ go doc github.com/ryszard/goskiplist/skiplist
Other implementations
=====================This list is probably incomplete.
* https://github.com/huandu/skiplist
* https://bitbucket.org/taruti/go-skip/src
* http://code.google.com/p/leveldb-go/source/browse/leveldb/memdb/memdb.go
(part of [leveldb-go](http://code.google.com/p/leveldb-go/))