store

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemStore

type InMemStore[K comparable, T any] struct {
	// contains filtered or unexported fields
}

InMemStore in-memory peer store

func NewInMemStore

func NewInMemStore[K comparable, V any]() *InMemStore[K, V]

NewInMemStore creates a new in-memory peer store

func (*InMemStore[K, T]) All

func (p *InMemStore[K, T]) All() []T

All returns all stored values in the store

func (*InMemStore[K, T]) Delete

func (p *InMemStore[K, T]) Delete(key K)

Delete removes the peer data from the store

func (*InMemStore[K, T]) Get

func (p *InMemStore[K, T]) Get(key K) (T, bool)

Get returns peer's data and true if the peer is found otherwise empty structure and false

func (*InMemStore[K, T]) GetAndDelete

func (p *InMemStore[K, T]) GetAndDelete(key K) (T, bool)

GetAndDelete combines Get operation and Delete in one call

func (*InMemStore[K, T]) IsZero

func (p *InMemStore[K, T]) IsZero() bool

IsZero returns true if the store doesn't have a peer yet otherwise false

func (*InMemStore[K, T]) Len

func (p *InMemStore[K, T]) Len() int

Len returns the count of all stored values

func (*InMemStore[K, T]) Put

func (p *InMemStore[K, T]) Put(key K, data T)

Put adds the peer data to the store if the peer does not exist, otherwise update the current value

func (*InMemStore[K, T]) Query

func (p *InMemStore[K, T]) Query(spec QueryFunc[K, T], limit int) []T

Query finds and returns the copy of values by specification conditions

func (*InMemStore[K, T]) Update

func (p *InMemStore[K, T]) Update(key K, updates ...UpdateFunc[K, T])

Update applies update functions to the peer if it exists

type QueryFunc

type QueryFunc[K comparable, V any] func(key K, data V) bool

QueryFunc is a function type for a specification function

func AndX

func AndX[K comparable, V any](specs ...QueryFunc[K, V]) QueryFunc[K, V]

AndX combines multiple specification functions into one

type Store

type Store[K comparable, V any] interface {
	Get(key K) (V, bool)
	GetAndDelete(key K) (V, bool)
	Put(key K, data V)
	Delete(key K)
	Update(key K, updates ...UpdateFunc[K, V])
	Query(spec QueryFunc[K, V], limit int) []V
	All() []V
	Len() int
	IsZero() bool
}

type UpdateFunc

type UpdateFunc[K comparable, V any] func(key K, item *V)

UpdateFunc is a function type for an item update functions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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