util

package
v0.0.0-...-c362759 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MapPoolSize = 4

Variables

View Source
var NonPrimitiveTypeError error = errors.New("Type provided to read/write does not fit inside 8 bytes.")

NonPrimitiveTypeError represents an error where the user provided a non-primitive data type for reading/writing

Functions

func GetArchType

func GetArchType(labels map[string]string) (string, bool)

func GetInstanceType

func GetInstanceType(labels map[string]string) (string, bool)

func GetOperatingSystem

func GetOperatingSystem(labels map[string]string) (string, bool)

func GetRegion

func GetRegion(labels map[string]string) (string, bool)

func GetZone

func GetZone(labels map[string]string) (string, bool)

func IsApproximately

func IsApproximately(a, b float64) bool

IsApproximately returns true is a approximately equals b, within a delta computed as a function of the size of a and b.

func IsWithin

func IsWithin(a, b, delta float64) bool

IsWithin returns true if a and b are within delta of each other

func VectorValue

func VectorValue(v float64, ok bool) *float64

returns a nil ptr or valid float ptr based on the ok bool

Types

type Buffer

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

Buffer is a utility type which implements a very basic binary protocol for writing core go types.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new Buffer instance using LittleEndian ByteOrder.

func NewBufferFrom

func NewBufferFrom(b *Buffer) *Buffer

NewBufferFrom creates a new Buffer instance using the remaining unread data from the provided Buffer instance. The new buffer assumes ownership of the underlying data.

func NewBufferFromBytes

func NewBufferFromBytes(b []byte) *Buffer

NewBufferFromBytes creates a new Buffer instance using the provided byte slice. The new buffer assumes ownership of the byte slice.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the unread portion of the underlying buffer storage.

func (*Buffer) ReadBool

func (b *Buffer) ReadBool() bool

ReadBool reads a bool value from the buffer.

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(length int) []byte

ReadBytes reads the specified length from the buffer and returns the byte slice.

func (*Buffer) ReadFloat32

func (b *Buffer) ReadFloat32() float32

ReadFloat32 reads a float32 value from the buffer.

func (*Buffer) ReadFloat64

func (b *Buffer) ReadFloat64() float64

ReadFloat64 reads a float64 value from the buffer.

func (*Buffer) ReadInt

func (b *Buffer) ReadInt() int

ReadInt reads an int value from the buffer.

func (*Buffer) ReadInt16

func (b *Buffer) ReadInt16() int16

ReadInt16 reads an int16 value from the buffer.

func (*Buffer) ReadInt32

func (b *Buffer) ReadInt32() int32

ReadInt32 reads an int32 value from the buffer.

func (*Buffer) ReadInt64

func (b *Buffer) ReadInt64() int64

ReadInt64 reads an int64 value from the buffer.

func (*Buffer) ReadInt8

func (b *Buffer) ReadInt8() int8

ReadInt8 reads an int8 value from the buffer.

func (*Buffer) ReadString

func (b *Buffer) ReadString() string

ReadString reads a uint16 value from the buffer representing the string's length, then uses the length to extract the exact length []byte representing the string.

func (*Buffer) ReadUInt

func (b *Buffer) ReadUInt() uint

ReadUInt reads a uint value from the buffer.

func (*Buffer) ReadUInt16

func (b *Buffer) ReadUInt16() uint16

ReadUInt16 reads a uint16 value from the buffer.

func (*Buffer) ReadUInt32

func (b *Buffer) ReadUInt32() uint32

ReadUInt32 reads a uint32 value from the buffer.

func (*Buffer) ReadUInt64

func (b *Buffer) ReadUInt64() uint64

ReadUInt64 reads a uint64 value from the buffer.

func (*Buffer) ReadUInt8

func (b *Buffer) ReadUInt8() uint8

ReadUInt8 reads a uint8 value from the buffer.

func (*Buffer) WriteBool

func (b *Buffer) WriteBool(t bool)

WriteBool writes a bool value to the buffer.

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(bytes []byte)

WriteBytes writes the contents of the byte slice to the buffer.

func (*Buffer) WriteFloat32

func (b *Buffer) WriteFloat32(i float32)

WriteFloat32 writes a float32 value to the buffer.

func (*Buffer) WriteFloat64

func (b *Buffer) WriteFloat64(i float64)

WriteFloat64 writes a float64 value to the buffer.

func (*Buffer) WriteInt

func (b *Buffer) WriteInt(i int)

WriteInt writes an int value to the buffer.

func (*Buffer) WriteInt16

func (b *Buffer) WriteInt16(i int16)

WriteInt16 writes an int16 value to the buffer.

func (*Buffer) WriteInt32

func (b *Buffer) WriteInt32(i int32)

WriteInt32 writes an int32 value to the buffer.

func (*Buffer) WriteInt64

func (b *Buffer) WriteInt64(i int64)

WriteInt64 writes an int64 value to the buffer.

func (*Buffer) WriteInt8

func (b *Buffer) WriteInt8(i int8)

WriteInt8 writes an int8 value to the buffer.

func (*Buffer) WriteString

func (b *Buffer) WriteString(i string)

WriteString writes the string's length as a uint16 followed by the string contents.

func (*Buffer) WriteUInt

func (b *Buffer) WriteUInt(i uint)

WriteUInt writes a uint value to the buffer.

func (*Buffer) WriteUInt16

func (b *Buffer) WriteUInt16(i uint16)

WriteUInt16 writes a uint16 value to the buffer.

func (*Buffer) WriteUInt32

func (b *Buffer) WriteUInt32(i uint32)

WriteUInt32 writes a uint32 value to the buffer.

func (*Buffer) WriteUInt64

func (b *Buffer) WriteUInt64(i uint64)

WriteUInt64 writes a uint64 value to the buffer.

func (*Buffer) WriteUInt8

func (b *Buffer) WriteUInt8(i uint8)

WriteUInt8 writes a uint8 value to the buffer.

type FixedMapPool

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

A buffered channel implementation of a vector map pool which controls the total number of maps allowed in/out of the pool at any given moment. Attempting to Get() with no available maps will block until one is available. You will be unable to Put() a map if the buffer is full.

func (*FixedMapPool) Get

func (mp *FixedMapPool) Get() map[uint64]float64

Returns a map from the pool. Blocks if no maps are available for re-use

func (*FixedMapPool) Put

func (mp *FixedMapPool) Put(m map[uint64]float64)

Adds a map back to the pool if there is room. Does not block on overflow.

type FlexibleMapPool

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

A buffered channel implementation of a vector map pool which controls the total number of maps allowed in/out of the pool at any given moment. Unlike the FixedMapPool, this pool will not block if maps are over requested, but will only maintain a buffer up the size limitation.

func (*FlexibleMapPool) Get

func (mp *FlexibleMapPool) Get() map[uint64]float64

Returns a map from the pool. Does not block on over-request.

func (*FlexibleMapPool) Put

func (mp *FlexibleMapPool) Put(m map[uint64]float64)

Adds a map back to the pool if there is room. Does not block on overflow.

type Semaphore

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

Semaphore implements a non-weighted semaphore for restricting concurrent access to a limited number of processes.

func NewSemaphore

func NewSemaphore(max int) *Semaphore

NewSemaphore creates a new Semaphore that allows max number of concurrent access

func (*Semaphore) Acquire

func (s *Semaphore) Acquire()

Acquire blocks until access can be granted to the caller

func (*Semaphore) Return

func (s *Semaphore) Return()

Return releases access from the caller, opening it for acquisition

type UnboundedMapPool

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

Implementation backed by sync.Pool

func (*UnboundedMapPool) Get

func (mp *UnboundedMapPool) Get() map[uint64]float64

Returns a map from the pool. Does not block on over-request.

func (*UnboundedMapPool) Put

func (mp *UnboundedMapPool) Put(m map[uint64]float64)

Adds a map back to the pool if there is room. Does not block on overflow.

type Vector

type Vector struct {
	Timestamp float64 `json:"timestamp"`
	Value     float64 `json:"value"`
}

func ApplyVectorOp

func ApplyVectorOp(xvs []*Vector, yvs []*Vector, op VectorJoinOp) []*Vector

ApplyVectorOp accepts two vectors, synchronizes timestamps, and executes an operation on each vector. See VectorJoinOp for details.

func NormalizeVectorByVector

func NormalizeVectorByVector(xvs []*Vector, yvs []*Vector) []*Vector

NormalizeVectorByVector produces a version of xvs (a slice of Vectors) which has had its timestamps rounded and its values divided by the values of the Vectors of yvs, such that yvs is the "unit" Vector slice.

type VectorJoinOp

type VectorJoinOp func(result *Vector, x *float64, y *float64) bool

VectorJoinOp is an operation func that accepts a result vector pointer for a specific timestamp and two float64 pointers representing the input vectors for that timestamp. x or y inputs can be nil, but not both. The op should use x and y values to set the Value on the result ptr. If a result could not be generated, the op should return false, which will omit the vector for the specific timestamp. Otherwise, return true denoting a successful op.

type VectorMapPool

type VectorMapPool interface {
	Get() map[uint64]float64
	Put(map[uint64]float64)
}

A pool of vector maps for mapping float64 timestamps to float64 values

func NewFixedMapPool

func NewFixedMapPool(size int) VectorMapPool

Creates a new fixed map pool which maintains a fixed pool size

func NewFlexibleMapPool

func NewFlexibleMapPool(size int) VectorMapPool

Creates a new fixed map pool which maintains a fixed pool size

func NewUnboundedMapPool

func NewUnboundedMapPool() VectorMapPool

Creates a new unbounded map pool which allows the runtime to decide when pooled values should be evicted

type VectorSlice

type VectorSlice []*Vector

func (VectorSlice) Len

func (p VectorSlice) Len() int

func (VectorSlice) Less

func (p VectorSlice) Less(i, j int) bool

func (VectorSlice) Swap

func (p VectorSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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