common

package
v0.0.0-...-437c9e2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeFromString

func DecodeFromString(hexString string) ([]byte, error)

DecodeFromString converts a hex string with 0X prefix to a byte slice

func EncodeToString

func EncodeToString(hexBytes []byte) string

EncodeToString returns the UPPERCASE string representation of hexBytes with the 0X prefix

func Is

func Is(err error, t StoreErrType) bool

func NewTestLogger

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

NewTestLogger is a factory method

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) *RollingIndexMap

func (*RollingIndexMap) AddKey

func (rim *RollingIndexMap) AddKey(key uint32) error

func (*RollingIndexMap) Get

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

return key items with index > skip

func (*RollingIndexMap) GetItem

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

func (*RollingIndexMap) GetLast

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

func (*RollingIndexMap) Known

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

returns [key] => lastKnownIndex

func (*RollingIndexMap) Set

func (rim *RollingIndexMap) Set(key uint32, 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
	KeyAlreadyExists
	NoPeerSet
)

type Trilean

type Trilean int
const (
	Undefined Trilean = iota
	True
	False
)

func (Trilean) String

func (t Trilean) String() string

Jump to

Keyboard shortcuts

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