kvstore

package
v0.0.0-...-8fa78e2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface[K constraints.Ordered, V ValueInterface] interface {
	// Get looks up a key's value from the key-value store. Ok is false if not found.
	Get(key K) (value *V, ok bool)
	// Set sets a value to the key-value store with key, replacing any existing value.
	Set(key K, val *V)
	// Keys returns the keys of the key-value store. The order is relied on algorithms.
	Keys() []K
	// Delete deletes the item with provided key from the key-value store.
	Delete(key K)
	// Contains reports whether the given key is stored within the key-value store.
	Contains(key K) bool
	// Iterate iterates over all the items in the key-value store and calls given function with key, value and options.
	Iterate(fn func(key K, value *V) error) error
}

Interface is a common key-value store interface.

type Item

type Item[K constraints.Ordered, V ValueInterface] struct {
	Key   K
	Value V
}

Item is an kvstore item

type KVStore

type KVStore[K constraints.Ordered, V ValueInterface] struct {
	// contains filtered or unexported fields
}

KVStore is a thread safe key-value store.

func New

func New[K constraints.Ordered, V ValueInterface]() *KVStore[K, V]

New creates a new thread safe key-value store.

func (*KVStore[K, V]) Contains

func (c *KVStore[K, V]) Contains(key K) bool

Contains reports whether the given key is stored within the key-value store.

func (*KVStore[K, V]) Delete

func (c *KVStore[K, V]) Delete(key K)

Delete deletes the item identified with the given key from the key-value store.

func (*KVStore[K, V]) Get

func (c *KVStore[K, V]) Get(key K) (value V, ok bool)

Get looks up a key's value from the key-value store.

func (*KVStore[K, V]) Iterate

func (c *KVStore[K, V]) Iterate(fn func(key K, value V) error) error

Iterate iterates over all the items in the key-value store and calls given function with key, value and options.

func (*KVStore[K, V]) Keys

func (c *KVStore[K, V]) Keys() []K

Keys returns the keys of the key-value store. The order is sorted from low to high (i.e. a-Z).

func (*KVStore[K, V]) Set

func (c *KVStore[K, V]) Set(key K, val V)

Set sets a value to the key-value store with key. Replacing any existing value.

type ValueInterface

type ValueInterface interface {
}

ValueInterface is a common value interface.

Jump to

Keyboard shortcuts

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