All Projects → Avalanche-io → sled

Avalanche-io / sled

Licence: other
A high performance lock free map type for go.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to sled

lfqueue
lock-free FIFO queue by C native built it, easy built cross platform(no extra dependencies needed) , guarantee thread safety memory management ever!
Stars: ✭ 104 (+477.78%)
Mutual labels:  lock-free, thread-safety
lfqueue
Minimize lock-free queue ever!
Stars: ✭ 107 (+494.44%)
Mutual labels:  lock-free, thread-safety
Xenium
A C++ library providing various concurrent data structures and reclamation schemes.
Stars: ✭ 225 (+1150%)
Mutual labels:  lock-free
lock-free-queue
CN-CppUserGroup-2019-1,lock-free queue demo
Stars: ✭ 58 (+222.22%)
Mutual labels:  lock-free
lockfree
⚡️ lock-free utilities in Go
Stars: ✭ 109 (+505.56%)
Mutual labels:  lock-free
Nonblocking
Implementation of a lock-free dictionary on .Net.
Stars: ✭ 237 (+1216.67%)
Mutual labels:  lock-free
zedis
A tiny embedded, lock free, redis-like, pub+sub, brokerless, key value datastore. ømq+sled
Stars: ✭ 33 (+83.33%)
Mutual labels:  lock-free
Multiqueue
A fast mpmc queue with broadcast capabilities
Stars: ✭ 167 (+827.78%)
Mutual labels:  lock-free
fifo-rs
A first-in-first-out for bytes, like kfifo in Linux.
Stars: ✭ 18 (+0%)
Mutual labels:  lock-free
send wrapper
No description or website provided.
Stars: ✭ 39 (+116.67%)
Mutual labels:  thread-safety
gdax-orderbook-hpp
An in-memory copy of the order book on the GDAX cryptocurrency exchange, updated in real time via WebSocket feed, exposed in a thread-safe and lock-free data structure.
Stars: ✭ 38 (+111.11%)
Mutual labels:  lock-free
concurrent-ll
concurrent linked list implementation
Stars: ✭ 66 (+266.67%)
Mutual labels:  lock-free
Jctools
jctools.github.io/jctools
Stars: ✭ 2,833 (+15638.89%)
Mutual labels:  lock-free
fcgi-function
A cross-platform module to writing C/C++ service for nginx.
Stars: ✭ 33 (+83.33%)
Mutual labels:  lock-free
Ringbuf
Lock-free ring buffer (MPSC)
Stars: ✭ 227 (+1161.11%)
Mutual labels:  lock-free
LFTPool
Lock-Free Thread Pool
Stars: ✭ 69 (+283.33%)
Mutual labels:  lock-free
Bwtree
An open sourced implementation of Bw-Tree in SQL Server Hekaton
Stars: ✭ 208 (+1055.56%)
Mutual labels:  lock-free
async
async is a tiny C++ header-only high-performance library for async calls handled by a thread-pool, which is built on top of an unbounded MPMC lock-free queue.
Stars: ✭ 25 (+38.89%)
Mutual labels:  lock-free
lock-free
Lock-Free data structures
Stars: ✭ 37 (+105.56%)
Mutual labels:  lock-free
optimistic lock coupling rs
🍋: A General Lock following paper "Optimistic Lock Coupling: A Scalable and Efficient General-Purpose Synchronization Method"
Stars: ✭ 21 (+16.67%)
Mutual labels:  lock-free

Sled

GoDoc Go Report Card Build Status Coverage Status

Sled is a high performance Key/Value store based on a ctrie data structure. Sled is non-blocking and thread safe, meaning it is safe to access from any number of threads simultaneously.

Any type of data can be stored in a key, but sled maintains the benefits of the Go type system by enforcing the type. Values must be accessed by passing an empty type value of the same type into the Get method.

Usage

go get "github.com/Avalanche-io/sled"

Create a sled with sled.New().

sl := sled.New()

Setting a key. Sled accepts any type.

sl.Set("key", "value")
sl.Set("Answer to the Ultimate Question", 42)
sl.Set("primes", []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29})

Getting a value.

var primes []int
var ultimate_answer int
var right_value_type string
var wrong_value_type []byte

err := sl.Get("Answer to the Ultimate Question", &ultimate_answer)
fmt.Printf("Answer to the Ultimate Question: %d, err: %t\n", ultimate_answer, err != nil)
err = sl.Get("primes", &primes)
fmt.Printf("Primes: %v, err: %t\n", primes, err != nil)
err = sl.Get("key", &wrong_value_type)
fmt.Printf("key: %v, err: %t\n", right_value_type, err != nil)
fmt.Printf("key (wrong type): %v, err: %s\n", wrong_value_type, err)
err = sl.Get("key", &right_value_type)

Setting a key conditionally. SetIfNil will only assign the value if the key is not already set.

SetIfNil(string, interface{}) bool

Deleting a key.

Delete(string) (interface{}, bool)

Close, when done with a sled close it, to free resources.

Close() error

Iterating over all keys, can be done with range expression.

stop := chan struct{} // or nil if interruption isn't needed.
for elm := range sl.Iterate(stop) {
    fmt.Printf("key: %s  value: %v\n", elm.Key(), elm.Value())
    elm.Close() // close the Element when done 
}

A Snapshot is a nearly zero cost copy of a sled that will not be effected by future changes to the source sled. It can be made mutable or immutable by setting the argument to sled.ReadWrite, or sled.ReadOnly.

sl_mutable := sl.Snapshot(sled.ReadWrite)
sl_immutable := sl.Snapshot(sled.ReadOnly)

Example

package main

import (
    "fmt"

    "github.com/Avalanche-io/sled"
)

func main() {
    sl := sled.New()

    key := "The meaning of life"
    sl.Set(key, 42)
    
    var v int
    err := sl.Get(key, &v)
    if err != nil {
        panic(err)
    }
    fmt.Printf("key: %s, \tvalue: %v\n", key, v)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].