common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash32

func Hash32(data []byte) int

func Is

func Is(err error, t StoreErrType) bool

func NewTestLogger

func NewTestLogger(t testing.TB) *logrus.Logger

Types

type EvictCallback

type EvictCallback func(key interface{}, value interface{})

EvictCallback is used to get a callback when a cache entry is evicted

type LRU

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

LRU implements a non-thread safe fixed size LRU cache

func NewLRU

func NewLRU(size int, onEvict EvictCallback) *LRU

NewLRU constructs an LRU of the given size

func (*LRU) Add

func (c *LRU) Add(key, value interface{}) bool

Add adds a value to the cache. Returns true if an eviction occurred.

func (*LRU) Contains

func (c *LRU) Contains(key interface{}) (ok bool)

Check if a key is in the cache, without updating the recent-ness or deleting it for being stale.

func (*LRU) Get

func (c *LRU) Get(key interface{}) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*LRU) GetOldest

func (c *LRU) GetOldest() (interface{}, interface{}, bool)

GetOldest returns the oldest entry

func (*LRU) Keys

func (c *LRU) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*LRU) Len

func (c *LRU) Len() int

Len returns the number of items in the cache.

func (*LRU) Peek

func (c *LRU) Peek(key interface{}) (value interface{}, ok bool)

Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

func (*LRU) Purge

func (c *LRU) Purge()

Purge is used to completely clear the cache

func (*LRU) Remove

func (c *LRU) Remove(key interface{}) bool

Remove removes the provided key from the cache, returning if the key was contained.

func (*LRU) RemoveOldest

func (c *LRU) RemoveOldest() (interface{}, interface{}, bool)

RemoveOldest removes the oldest item from the cache.

type RollingIndex

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

func NewRollingIndex

func NewRollingIndex(name string, size int) *RollingIndex

func (*RollingIndex) Get

func (r *RollingIndex) Get(skipIndex int) ([]interface{}, error)

func (*RollingIndex) GetItem

func (r *RollingIndex) GetItem(index int) (interface{}, error)

func (*RollingIndex) GetLastWindow

func (r *RollingIndex) GetLastWindow() (lastWindow []interface{}, lastIndex int)

func (*RollingIndex) Roll

func (r *RollingIndex) Roll()

func (*RollingIndex) Set

func (r *RollingIndex) Set(item interface{}, index int) error

type RollingIndexMap

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

func NewRollingIndexMap

func NewRollingIndexMap(name string, size int, keys []int) *RollingIndexMap

func (*RollingIndexMap) Get

func (rim *RollingIndexMap) Get(key int, skipIndex int) ([]interface{}, error)

return key items with index > skip

func (*RollingIndexMap) GetItem

func (rim *RollingIndexMap) GetItem(key int, index int) (interface{}, error)

func (*RollingIndexMap) GetLast

func (rim *RollingIndexMap) GetLast(key int) (interface{}, error)

func (*RollingIndexMap) Known

func (rim *RollingIndexMap) Known() map[int]int

returns [key] => lastKnownIndex

func (*RollingIndexMap) Reset

func (rim *RollingIndexMap) Reset() error

func (*RollingIndexMap) Set

func (rim *RollingIndexMap) Set(key int, item interface{}, index int) error

type StoreErr

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

func NewStoreErr

func NewStoreErr(dataType string, errType StoreErrType, key string) StoreErr

func (StoreErr) Error

func (e StoreErr) Error() string

type StoreErrType

type StoreErrType uint32
const (
	KeyNotFound StoreErrType = iota
	TooLate
	PassedIndex
	SkippedIndex
	NoRoot
	UnknownParticipant
	Empty
)

Jump to

Keyboard shortcuts

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