common

package
v0.0.0-...-50e3d47 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 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

Is ...

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
}

RollingIndex ...

func NewRollingIndex

func NewRollingIndex(name string, size int) *RollingIndex

NewRollingIndex ...

func (*RollingIndex) Get

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

Get ...

func (*RollingIndex) GetItem

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

GetItem ...

func (*RollingIndex) GetLastWindow

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

GetLastWindow ...

func (*RollingIndex) Roll

func (r *RollingIndex) Roll()

Roll ...

func (*RollingIndex) Set

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

Set ...

type RollingIndexMap

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

RollingIndexMap ...

func NewRollingIndexMap

func NewRollingIndexMap(name string, size int) *RollingIndexMap

NewRollingIndexMap ...

func (*RollingIndexMap) AddKey

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

AddKey ...

func (*RollingIndexMap) Get

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

Get return key items with index > skip

func (*RollingIndexMap) GetItem

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

GetItem ...

func (*RollingIndexMap) GetLast

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

GetLast ...

func (*RollingIndexMap) Known

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

Known returns [key] => lastKnownIndex

func (*RollingIndexMap) Set

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

Set ...

type StoreErr

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

StoreErr ...

func NewStoreErr

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

NewStoreErr ...

func (StoreErr) Error

func (e StoreErr) Error() string

Error ...

type StoreErrType

type StoreErrType uint32

StoreErrType ...

const (
	// KeyNotFound ...
	KeyNotFound StoreErrType = iota
	// TooLate ...
	TooLate
	// PassedIndex ...
	PassedIndex
	// SkippedIndex ...
	SkippedIndex
	// NoRoot ...
	NoRoot
	// UnknownParticipant ...
	UnknownParticipant
	// Empty ...
	Empty
	// KeyAlreadyExists ...
	KeyAlreadyExists
	// NoPeerSet ...
	NoPeerSet
)

type Trilean

type Trilean int

Trilean ...

const (
	// Undefined ...
	Undefined Trilean = iota
	// True ...
	True
	// False ...
	False
)

func (Trilean) String

func (t Trilean) String() string

String ...

Jump to

Keyboard shortcuts

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