Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Skip list implemented in Go.
Go Shell
branch: master

Merge pull request #2 from cburkert/patch-1

Fixed copy paste error in URL travis-ci status
latest commit 7ab5ac951b
@huandu authored
Failed to load latest commit information.
.gitignore refs #1. go fmt; doc update.
.travis.yml refs #1. go fmt; doc update.
LICENSE init
README.md Fixed copy paste error in URL travis-ci status
element.go
gen_compare_funcs.sh refs #1. go fmt; doc update.
skiplist.go
skiplist_test.go refs #1. go fmt; doc update.
type.go refs #1. go fmt; doc update.
var.go

README.md

Skip List in Golang

Build Status GoDoc

Skip list is a kind of ordered map and can store any value inside. See skip list wikipedia page to learn more about this data structure.

Highlights in this implementation:

  • Support custom compare function so that any type can be used as key.
  • Key sort order can be changed quite easily.
  • Rand source and max level can be changed per list. It can be useful in performance critical scenarios.

How To Use

Install this package through go get.

go get github.com/huandu/skiplist

Use it as following.

package main

import (
    "fmt"
    "github.com/huandu/skiplist"
)

func main() {
    // Create a skip list with int key.
    list := skiplist.New(skiplist.Int)

    // Add some values. Value can be anything.
    list.Set(12, "hello world")
    list.Set(34, 56)

    // Get element by index.
    elem := list.Get(34) // Value is stored in elem.Value.
    fmt.Println(elem.Value)
    next := elem.Next()  // Get next element.
    fmt.Println(next.Value)

    // Or get value directly just like a map
    val, ok := list.GetValue(34)
    fmt.Println(val, ok)

    // Remove an element by index.
    list.Remove(34)
}

License

This library is licensed under MIT license. See LICENSE for details.

Something went wrong with that request. Please try again.