gorivets

package module
v0.0.0-...-669d3f1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: Apache-2.0 Imports: 10 Imported by: 12

README

gorivets

Build Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt64

func AbsInt64(val int64) int64

func AssertNoError

func AssertNoError(err error)

Calls panic with the error description if the err is not nil

func AssertNotNil

func AssertNotNil(inf interface{})

func AssertNotNilMsg

func AssertNotNilMsg(inf interface{}, msg string)

func CheckPanic

func CheckPanic(f func()) (result interface{})

Invokes the function and returns whether it panics or not

func CompareInt

func CompareInt(a int, b int) int

func EndQuietly

func EndQuietly()

Calls recover() to consume panic if it happened, it is recomended to be used with defer:

func TestNoPanic() {
	defer EndQuietly()
	panic()
}

func FormatInt64

func FormatInt64(val int64, scale int) string

Formats val as 1000 power scale ("kb", "mb", "gb", "tb", "pb"), or 1024 power ("kib", "mib", "gib", "tib", "pib"), or just removes value as is

func GMapCleanup

func GMapCleanup()

Cleans up the storage and removes the temporary file if it exists. All consequential calls of GMapPut() will cause of re-initilization of the Global Map what will require to call the GMapCleanup() once again.

func GMapDelete

func GMapDelete(key string) interface{}

Deletes a value by its key. If the storage becomes empty the deleteGMap() will be called

func GMapGet

func GMapGet(key string) (interface{}, bool)

Returns a value by key. It returns whether the key-value pair is in the storage in the second bool parameter

func GMapPut

func GMapPut(key string, value interface{}) (interface{}, bool)

Puts a value by key. It returns previously stored value if it was there. Second returned parameter indicates whether there was a value for the key before the call

func IsNil

func IsNil(inf interface{}) bool

func Max

func Max(a, b int) int

Returns a maximal value of two integers provided

func Min

func Min(a, b int) int

Returns minimal value of two integers provided

func ParseBool

func ParseBool(value string, defaultValue bool) (bool, error)

Parses boolean value removing leading or trailing spaces if present

func ParseInt

func ParseInt(value string, min, max, defaultValue int) (int, error)

Parses string to int value, see ParseInt64

func ParseInt64

func ParseInt64(value string, min, max, defaultValue int64) (int64, error)

ParseInt64 tries to convert value to int64, or returns default if the value is empty string. The value can look like "12Kb" which means 12*1000, or "12Kib" which means 12*1024. The following suffixes are supported for scaling by 1000 each: "kb", "mb", "gb", "tb", "pb", or "k", "m", "g", "t", "p". For 1024 scale the following suffixes are supported: "kib", "mib", "gib", "tib", "pib"

Types

type Comparable

type Comparable interface {
	Compare(other Comparable) int
}

type CompareF

type CompareF func(a, b interface{}) int

CompareF is used in collections to compare elements if some ordering is needed please see `SortedSlice` as an example. It compares 2 objects a and b and returns a value(val): val < 0 if a < b, val == 0 if a == b, and val > 0 if a > b

type Int64

type Int64 int64

func (Int64) Compare

func (i Int64) Compare(other Comparable) int

type LRU

type LRU interface {
	// Add an element to the LRU.
	Add(k, v interface{}, size int64)
	// returns the element and marks it as recently used
	Get(k interface{}) (interface{}, bool)
	// returns the element, but not marking it as used recently
	Peek(k interface{}) (interface{}, bool)

	// Deletes an element and call for callback if it is not nil
	// equivavalent to DeleteWithCallback(k, true)
	Delete(k interface{}) interface{}

	// Deletes an elementa and call callback function if callback==true and
	// the callback function was specified for the container
	DeleteWithCallback(k interface{}, callback bool) interface{}

	// Garbage collection call, can be needed for time restricted LRU
	Sweep()
	Clear()
	// Multithread: friendly
	Len() int
	// Multithread: friendly
	Size() int64
}

Least Recently Used container interface. Defines basic methods for different implementations (see sized and time-based below).

Method calls should be guarded by synchronization primitives in multi-thread environment, unless it's explicitly said "friendly"

func NewLRU

func NewLRU(maxSize int64, callback LruCallback) LRU

func NewTtlLRU

func NewTtlLRU(maxSize int64, duration time.Duration, callback LruCallback) LRU

type Logger

type Logger interface {
	Fatal(args ...interface{})
	Error(args ...interface{})
	Warn(args ...interface{})
	Info(args ...interface{})
	Debug(args ...interface{})
	Trace(args ...interface{})

	WithId(id interface{}) interface{}
	WithName(name string) interface{}
}

type Lru

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

func (*Lru) Add

func (lru *Lru) Add(k, v interface{}, size int64)

=============================== Lru =======================================

func (*Lru) Clear

func (lru *Lru) Clear()

Clear the cache. This method will not invoke callbacks for the deleted elements

func (*Lru) Delete

func (lru *Lru) Delete(k interface{}) interface{}

func (*Lru) DeleteWithCallback

func (lru *Lru) DeleteWithCallback(k interface{}, callback bool) interface{}

func (*Lru) Get

func (lru *Lru) Get(k interface{}) (interface{}, bool)

func (*Lru) Len

func (lru *Lru) Len() int

func (*Lru) Peek

func (lru *Lru) Peek(k interface{}) (interface{}, bool)

func (*Lru) Size

func (lru *Lru) Size() int64

func (*Lru) Sweep

func (lru *Lru) Sweep()

type LruCallback

type LruCallback func(k, v interface{})

type NewLoggerF

type NewLoggerF func(name string) Logger

func NewNilLoggerProvider

func NewNilLoggerProvider() NewLoggerF

func NewStubLoggerProvider

func NewStubLoggerProvider() NewLoggerF

type SortedSlice

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

func NewSortedSlice

func NewSortedSlice(initialCapacity int) (*SortedSlice, error)

func NewSortedSliceByComp

func NewSortedSliceByComp(compF CompareF, initialCapacity int) (*SortedSlice, error)

func NewSortedSliceByCompAndParams

func NewSortedSliceByCompAndParams(compF CompareF, data ...interface{}) (*SortedSlice, error)

func NewSortedSliceByParams

func NewSortedSliceByParams(data ...interface{}) (*SortedSlice, error)

func (*SortedSlice) Add

func (ss *SortedSlice) Add(val interface{}) (int, error)

func (*SortedSlice) At

func (ss *SortedSlice) At(idx int) interface{}

func (*SortedSlice) Copy

func (ss *SortedSlice) Copy() []interface{}

func (*SortedSlice) Delete

func (ss *SortedSlice) Delete(val interface{}) bool

func (*SortedSlice) DeleteAt

func (ss *SortedSlice) DeleteAt(idx int) interface{}

func (*SortedSlice) Find

func (ss *SortedSlice) Find(val interface{}) (int, bool)

func (*SortedSlice) GetInsertPos

func (ss *SortedSlice) GetInsertPos(val interface{}) int

func (*SortedSlice) Len

func (ss *SortedSlice) Len() int

Jump to

Keyboard shortcuts

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