memstore

package module
v0.0.0-...-065f693 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2019 License: MIT Imports: 2 Imported by: 0

README

Memstore Travis CI Build Status Coverage license

Memstore is an in-memory, thread safe, multiple-key datastore for Go.

Overview

The datastore is built on top of multiple Left-Leaning Red-Black trees.

It allows you to store a collection of any arbitrary Go language structures, as long as you define a method to define comparison for arbitrary indexes.

It provides a way to get ranges based on any index in O(k + log n) time, k being the number of elements retrieved, and n being the number of structures in the datastore.

Also, getting minimum and maximum values based on any index defined runs O(log n).

All methods exported are thread safe, and enable multiple readers through a native Read Write Lock.

It's meant for use as a light-weight, efficient in-memory datastore as part of your Go package. If you want to persist data or advanced features (transactions, detailed search...etc), this may not not be ideal.

Installation

With a healthy Go Language installed, simply run go get github.com/mngharbi/memstore

Dependency

This package depends on GoLLRB, built by Petar Maymounkov.

However, I had to patch it to leverage it for this package. So, this package technically depends on the forked version.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface {
	Less(index string, than interface{}) bool
}

Interface for any element

Includes comparator for every index

type Memstore

type Memstore struct {
	// contains filtered or unexported fields
}

Memstore object Nothing is exported

func New

func New(indexes []string) *Memstore

func (*Memstore) Add

func (ms *Memstore) Add(x Item)

func (*Memstore) AddOrGet

func (ms *Memstore) AddOrGet(x Item) Item

func (*Memstore) ApplyData

func (ms *Memstore) ApplyData(x Item, index string, run func(Item) bool) (res Item)

func (*Memstore) ApplyDataSubset

func (ms *Memstore) ApplyDataSubset(items []Item, index string, apply func(Item) bool) (res []Item)

func (*Memstore) Delete

func (ms *Memstore) Delete(x Item, index string) Item

func (*Memstore) Get

func (ms *Memstore) Get(x Item, index string) (res Item)

func (*Memstore) GetRange

func (ms *Memstore) GetRange(from, to Item, index string, test func(Item) bool)

func (*Memstore) Len

func (ms *Memstore) Len() (res int)

func (*Memstore) Max

func (ms *Memstore) Max(index string) (res Item)

func (*Memstore) Min

func (ms *Memstore) Min(index string) (res Item)

func (*Memstore) UpdateData

func (ms *Memstore) UpdateData(x Item, index string, modify func(Item) (Item, bool)) (res Item)

func (*Memstore) UpdateWithIndexes

func (ms *Memstore) UpdateWithIndexes(x Item, index string, modify func(Item) (Item, bool)) (res Item)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL