lib

package
v0.0.0-...-b47ea92 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 11 Imported by: 5

README

Collection of library of functions

GoDoc

  • Contain useful functions and features that are not particularly tied up to any storage algorithm.
  • Implementations under this package must be self contained, and should not depend on anything other than standard library.
  • Shall not import gostore package or any of its sub-packages.

Panic and recover

  • Prettystats will panic if json.Marshal returns an error.

Documentation

Overview

Package lib provide useful functions and features that are not particularly tied up with any storage algorithm. They are meant to be small, self-contained and shall not depend on anything other than the standard library.

Index

Constants

This section is empty.

Variables

View Source
var ErrorUuidInvalidSize = errors.New("uuid.invalidsize")

ErrorUuidInvalidSize while generating uuid byte-string, the size of the byte-string shall be > 8 and shall be even numbered.

Functions

func AbsInt64

func AbsInt64(x int64) int64

AbsInt64 absolute value of int64 number. Except for -2^63, where returned value will be same as input.

func Bytes2str

func Bytes2str(bytes []byte) string

Bytes2str morph byte slice to a string without copying. Note that the source byte-slice should remain in scope as long as string is in scope.

func FailsafePost

func FailsafePost(
	reqch chan []interface{}, cmd []interface{}, finch chan struct{}) error

FailsafePost for gen-server design pattern. While posting a message to reqch channel, if i/p channel is full but gen-server has exited or crashed, prevent caller from blocking.

func FailsafeRequest

func FailsafeRequest(
	reqch, respch chan []interface{},
	cmd []interface{}, finch chan struct{}) ([]interface{}, error)

FailsafeRequest for gen-server design pattern. While posting a request to reqch channel, if channel is full but gen-server has exited or crashed, prevent caller from blocking. Similarly, while waiting for a response from respch channel, if gen-server has exited or crashed, prevent caller from blocking.

func Fixbuffer

func Fixbuffer(buffer []byte, size int64) []byte

Fixbuffer will expand the buffer if its capacity is less than size and return the buffer of size length.

func GetStacktrace

func GetStacktrace(skip int, stack []byte) string

GetStacktrace return stack-trace in human readable format.

func Memcpy

func Memcpy(dst, src unsafe.Pointer, ln int) int

Memcpy copy memory block of length `ln` from `src` to `dst`. This function is useful if memory block is obtained outside golang runtime.

func Parsecsv

func Parsecsv(input string) []string

Parsecsv convert a string of command seperated value into list of string of values.

func Prettystats

func Prettystats(stats map[string]interface{}, pretty bool) string

Prettystats uses, if pretty is true, json.MarshalIndent instead of json.Marshal. If Marshal return error Prettystats will panic.

func ResponseError

func ResponseError(err error, response []interface{}, idx int) error

ResponseError for gen-server design pattern. Return err is not nil, else type-cast idx-th element in response to error and return the same.

func Str2bytes

func Str2bytes(str string) []byte

Str2bytes morph string to a byte-slice without copying. Note that the source string should remain in scope as long as byte-slice is in scope.

Types

type AverageInt64

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

AverageInt64 compute statistical mean, median and variance for a sample set of int64 numbers.

func (*AverageInt64) Add

func (av *AverageInt64) Add(sample int64)

Add a new sample.

func (*AverageInt64) Clone

func (av *AverageInt64) Clone() *AverageInt64

Clone copies the entire instance.

func (*AverageInt64) Max

func (av *AverageInt64) Max() int64

Max return maximum value from sample.

func (*AverageInt64) Mean

func (av *AverageInt64) Mean() int64

Mean return the average value of all samples.

func (*AverageInt64) Min

func (av *AverageInt64) Min() int64

Min return minimum value from sample.

func (*AverageInt64) SD

func (av *AverageInt64) SD() int64

SD return by how much the samples differ from the mean value of sample set.

func (*AverageInt64) Samples

func (av *AverageInt64) Samples() int64

Samples return total number of samples in the set.

func (*AverageInt64) Stats

func (av *AverageInt64) Stats() map[string]interface{}

Stats return a map of statistics.

func (*AverageInt64) Sum

func (av *AverageInt64) Sum() int64

Sum return the sum of all sample values.

func (*AverageInt64) Variance

func (av *AverageInt64) Variance() int64

Variance return the squared deviation of a random sample from its mean.

type Bit32

type Bit32 uint32

Bit32 alias for uint32, provides bit twiddling methods on 32-bit number.

func (Bit32) Ones

func (b Bit32) Ones() int8

Ones return the count of 1s in this 32-bit value.

func (Bit32) Zeros

func (b Bit32) Zeros() int8

Zeros return the count 0z in this 32-bit value.

type Bit8

type Bit8 byte

Bit8 alias for byte, provides bit twiddling methods on 8-bit number.

func (Bit8) Clearbit

func (b Bit8) Clearbit(n uint8) byte

Clearbit clear the nth bit and return the new byte.

func (Bit8) Findfirstset

func (b Bit8) Findfirstset() int8

Findfirstset first bit set in byte.

func (Bit8) Ones

func (b Bit8) Ones() (c int8)

Ones return the count of 1s in this 8-bit value.

func (Bit8) Setbit

func (b Bit8) Setbit(n uint8) byte

Setbit set the nth bit and return the new byte.

func (Bit8) Zeros

func (b Bit8) Zeros() int8

Zeros return the count of 0s in this 8-bit value.

type HistogramInt64

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

HistogramInt64 statistical histogram.

func NewhistorgramInt64

func NewhistorgramInt64(from, till, width int64) *HistogramInt64

NewhistorgramInt64 return a new histogram object.

func (*HistogramInt64) Add

func (h *HistogramInt64) Add(sample int64)

Add a sample to this histogram.

func (*HistogramInt64) Clone

func (h *HistogramInt64) Clone() *HistogramInt64

Clone copies the entire instance.

func (*HistogramInt64) Fullstats

func (h *HistogramInt64) Fullstats() map[string]interface{}

Fullstats includes mean,variance,stddeviance in the Stats().

func (*HistogramInt64) Logstring

func (h *HistogramInt64) Logstring() string

Logstring return Fullstats as loggable string.

func (*HistogramInt64) Max

func (h *HistogramInt64) Max() int64

Max return maximum value from sample.

func (*HistogramInt64) Mean

func (h *HistogramInt64) Mean() int64

Mean return the average value of all samples.

func (*HistogramInt64) Min

func (h *HistogramInt64) Min() int64

Min return minimum value from sample.

func (*HistogramInt64) SD

func (h *HistogramInt64) SD() int64

SD return by how much the samples differ from the mean value of sample set.

func (*HistogramInt64) Samples

func (h *HistogramInt64) Samples() int64

Samples return total number of samples in the set.

func (*HistogramInt64) Stats

func (h *HistogramInt64) Stats() map[string]int64

Stats return a map of histogram.

func (*HistogramInt64) Sum

func (h *HistogramInt64) Sum() int64

Sum return the sum of all sample values.

func (*HistogramInt64) Variance

func (h *HistogramInt64) Variance() int64

Variance return the squared deviation of a random sample from its mean.

type Uuid

type Uuid []byte

Uuid bytes of values read from cyptro/rand.

func Allocuuid

func Allocuuid(size int) (Uuid, error)

Allocuuid like Newuuid but allocates a new set of bytes, instead of user supplied.

func Newuuid

func Newuuid(buf Uuid) (Uuid, error)

Newuuid populate buf with unique set of bytes.

func (Uuid) Format

func (uuid Uuid) Format(out []byte) int

Format uuid to hyphenated string.

Jump to

Keyboard shortcuts

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