Documentation ¶
Index ¶
- func AbsInt64(val int64) int64
- func AssertNoError(err error)
- func AssertNotNil(inf interface{})
- func AssertNotNilMsg(inf interface{}, msg string)
- func CheckPanic(f func()) (result interface{})
- func CompareInt(a int, b int) int
- func EndQuietly()
- func FormatInt64(val int64, scale int) string
- func GMapCleanup()
- func GMapDelete(key string) interface{}
- func GMapGet(key string) (interface{}, bool)
- func GMapPut(key string, value interface{}) (interface{}, bool)
- func IsNil(inf interface{}) bool
- func Max(a, b int) int
- func Min(a, b int) int
- func ParseBool(value string, defaultValue bool) (bool, error)
- func ParseInt(value string, min, max, defaultValue int) (int, error)
- func ParseInt64(value string, min, max, defaultValue int64) (int64, error)
- type Comparable
- type CompareF
- type Int64
- type LRU
- type Logger
- type Lru
- func (lru *Lru) Add(k, v interface{}, size int64)
- func (lru *Lru) Clear()
- func (lru *Lru) Delete(k interface{}) interface{}
- func (lru *Lru) DeleteWithCallback(k interface{}, callback bool) interface{}
- func (lru *Lru) Get(k interface{}) (interface{}, bool)
- func (lru *Lru) Len() int
- func (lru *Lru) Peek(k interface{}) (interface{}, bool)
- func (lru *Lru) Size() int64
- func (lru *Lru) Sweep()
- type LruCallback
- type NewLoggerF
- type SortedSlice
- func NewSortedSlice(initialCapacity int) (*SortedSlice, error)
- func NewSortedSliceByComp(compF CompareF, initialCapacity int) (*SortedSlice, error)
- func NewSortedSliceByCompAndParams(compF CompareF, data ...interface{}) (*SortedSlice, error)
- func NewSortedSliceByParams(data ...interface{}) (*SortedSlice, error)
- func (ss *SortedSlice) Add(val interface{}) (int, error)
- func (ss *SortedSlice) At(idx int) interface{}
- func (ss *SortedSlice) Copy() []interface{}
- func (ss *SortedSlice) Delete(val interface{}) bool
- func (ss *SortedSlice) DeleteAt(idx int) interface{}
- func (ss *SortedSlice) Find(val interface{}) (int, bool)
- func (ss *SortedSlice) GetInsertPos(val interface{}) int
- func (ss *SortedSlice) Len() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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 ¶
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 ¶
Returns a value by key. It returns whether the key-value pair is in the storage in the second bool parameter
func GMapPut ¶
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 ParseInt64 ¶
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 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
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) Clear ¶
func (lru *Lru) Clear()
Clear the cache. This method will not invoke callbacks for the deleted elements
func (*Lru) DeleteWithCallback ¶
type LruCallback ¶
type LruCallback func(k, v interface{})
type NewLoggerF ¶
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