utils

package
v0.10.12 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MPL-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const SecondsPerDay int64 = 86400

Variables

View Source
var Fixed8Decimals = int(math.Pow10(precision))

Fixed8Decimals represents 10^precision (100000000), a value of 1 in Fixed8 format

View Source
var Fixed8One = NewFixed8(1)

Functions

func AbsInt

func AbsInt(a int64) int64

func Compress

func Compress(bz []byte) ([]byte, error)

func ConcurrentExecuteAsync

func ConcurrentExecuteAsync(concurrency int, producer func(), consumer func(), postConsume func())

func ConcurrentExecuteSync

func ConcurrentExecuteSync(concurrency int, producer func(), consumer func())

func Int642Bytes

func Int642Bytes(n int64) []byte

func IsAlphaNum

func IsAlphaNum(s string) bool

func MaxInt

func MaxInt(a, b int64) int64

func MinInt

func MinInt(a, b int64) int64

func Mul64

func Mul64(a, b int64) (int64, bool)

func Now

func Now() time.Time

func ParsePrice

func ParsePrice(priceStr string) (int64, error)

func SameDayInUTC

func SameDayInUTC(first, second time.Time) bool

timestamp is from time.Unix()

Types

type Fixed8

type Fixed8 int64

Fixed8 represents a fixed-point number with precision 10^-8

func Fixed8DecodeString

func Fixed8DecodeString(s string) (Fixed8, error)

Fixed8DecodeString parses s which must be a fixed point number with precision up to 10^-8

func NewFixed8

func NewFixed8(val int64) Fixed8

NewFixed8 returns a new Fixed8 with the supplied int multiplied by 10^8

func (*Fixed8) MarshalJSON

func (f *Fixed8) MarshalJSON() ([]byte, error)

MarshalJSON implements the json marshaller interface

func (Fixed8) String

func (f Fixed8) String() string

String implements the Stringer interface

func (Fixed8) ToInt64

func (f Fixed8) ToInt64() int64

ToInt64 returns the original value representing the Fixed8

func (*Fixed8) UnmarshalJSON

func (f *Fixed8) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json unmarshaller interface

func (Fixed8) Value

func (f Fixed8) Value() int64

Value returns the original value representing the Fixed8 divided by 10^8

type FixedSizeRing

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

FixedSizeRing is well-designed for the scenario that we always push elements back and never pop elements If the ring is full, the newly pushed elements will override the oldest elements. not goroutine-safe

func NewFixedSizedRing

func NewFixedSizedRing(cap int64) *FixedSizeRing

func (*FixedSizeRing) Count

func (q *FixedSizeRing) Count() int64

func (*FixedSizeRing) Elements

func (q *FixedSizeRing) Elements() []interface{}

func (*FixedSizeRing) IsEmpty

func (q *FixedSizeRing) IsEmpty() bool

func (*FixedSizeRing) Push

func (q *FixedSizeRing) Push(v interface{}) *FixedSizeRing

func (*FixedSizeRing) String

func (q *FixedSizeRing) String() string

Jump to

Keyboard shortcuts

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