util

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPprofHost = "127.0.0.1"
	StorePprofPort   = "6060"
	SqlPprofPort     = "6061"
	MetaPprofPort    = "6062"
)
View Source
const (
	TierBegin          = 0
	Hot                = 1
	Warm               = 2
	Cold               = 3
	Moving             = 4
	Cleared            = 5
	NoClear            = 6
	Clearing           = 7
	TierEnd            = 8
	True               = "true"
	False              = "false"
	PrecisionThreshold = 1e-9
)
View Source
const (
	BooleanSizeBytes = int(unsafe.Sizeof(false))
	Uint32SizeBytes  = int(unsafe.Sizeof(uint32(0)))
	Uint16SizeBytes  = int(unsafe.Sizeof(uint16(0)))
	Uint64SizeBytes  = int(unsafe.Sizeof(uint64(0)))
	Int16SizeBytes   = int(unsafe.Sizeof(int16(0)))
	Int32SizeBytes   = int(unsafe.Sizeof(int32(0)))
	Int64SizeBytes   = int(unsafe.Sizeof(int64(0)))
	Float32SizeBytes = int(unsafe.Sizeof(float32(0)))
	Float64SizeBytes = int(unsafe.Sizeof(float64(0)))
	Int8SizeBytes    = int(unsafe.Sizeof(int8(0)))

	RowsNumPerFragment                int = 8192
	DefaultMaxRowsPerSegment4TsStore      = 1000
	DefaultMaxRowsPerSegment4ColStore     = RowsNumPerFragment // should be the same as RowsNumPerFragment@colstore
	DefaultMaxSegmentLimit4ColStore       = 256 * 1024
	DefaultMaxChunkMetaItemSize           = 256 * 1024
	DefaultMaxChunkMetaItemCount          = 512
	CompressModMaxChunkMetaItemCount      = 16

	NonStreamingCompact               = 2
	StreamingCompact                  = 1
	AutoCompact                       = 0
	DefaultExpectedSegmentSize uint32 = 8 * 1024 * 1024
	DefaultFileSizeLimit              = 8 * 1024 * 1024 * 1024

	DefaultEntryLogSizeLimit = 20 * 1024 * 1024 * 1024

	MaxMeasurementLengthWithVersion = 255
	// eg, version is:_0000
	MeasurementVersionLength = 5
	// the measurement name length should consider MeasurementVersionLength
	MaxMeasurementLength = MaxMeasurementLengthWithVersion - MeasurementVersionLength

	MaxTagNameLength   = 255
	MaxTagValueLength  = 64 * 1024
	MaxFieldNameLength = 255
)

Variables

View Source
var HttpsClient = &http.Client{
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	},
}

Functions

func AllocSlice added in v1.1.0

func AllocSlice[T allocItem](data []T, size int) ([]T, []T)

func Bool2Byte added in v1.5.0

func Bool2Byte(b bool) byte

func Bool2Int64 added in v1.5.0

func Bool2Int64(b bool) int64

func Bool2str added in v1.3.0

func Bool2str(b bool) string

func BooleanSlice2byte added in v1.1.0

func BooleanSlice2byte(b []bool) []byte

func Bytes2BooleanSlice added in v1.1.0

func Bytes2BooleanSlice(b []byte) []bool

func Bytes2Float32Slice added in v1.1.0

func Bytes2Float32Slice(b []byte) []float32

func Bytes2Float64Slice added in v1.1.0

func Bytes2Float64Slice(b []byte) []float64

func Bytes2Int16Slice added in v1.1.0

func Bytes2Int16Slice(b []byte) []int16

func Bytes2Int32Slice added in v1.1.0

func Bytes2Int32Slice(b []byte) []int32

func Bytes2Int64Slice added in v1.1.0

func Bytes2Int64Slice(b []byte) []int64

func Bytes2Int8Slice added in v1.1.0

func Bytes2Int8Slice(b []byte) []int8

func Bytes2Uint16Slice added in v1.1.0

func Bytes2Uint16Slice(b []byte) []uint16

func Bytes2Uint32Slice added in v1.1.0

func Bytes2Uint32Slice(b []byte) []uint32

func Bytes2Uint64Slice added in v1.1.0

func Bytes2Uint64Slice(b []byte) []uint64

func Bytes2Value added in v1.5.0

func Bytes2Value[T any](b []byte, v *T)

func Bytes2str added in v1.1.0

func Bytes2str(b []byte) string

func CeilToPower2 added in v0.2.0

func CeilToPower2(num uint64) uint64

func ClearingWhileReading added in v1.5.0

func ClearingWhileReading(startTier, endTier uint64) bool

func DivisionCeil added in v1.3.0

func DivisionCeil(dividend, divisor int) int

func FindIntersectionIndex added in v1.5.0

func FindIntersectionIndex[T1, T2 any](slice1 []T1, slice2 []T2,
	compareFunc func(T1, T2) int, callbackFunc func(i, j int) error) error

FindIntersectionIndex finds the intersection indices of two sorted slices based on a custom comparison function.

func Float32Slice2byte added in v1.1.0

func Float32Slice2byte(b []float32) []byte

func Float64Slice2byte added in v1.1.0

func Float64Slice2byte(b []float64) []byte

func Float64ToUint64 added in v1.1.0

func Float64ToUint64(v float64) uint64

func Include added in v1.0.0

func Include(slice []uint64, s uint64) bool

Include returns true or false if given array is in slice.

func IndexOf added in v1.0.0

func IndexOf(slice []uint64, s uint64) int

IndexOf returns index position in slice from given array If value is -1, the string does not found.

func Int16Slice2byte added in v1.1.0

func Int16Slice2byte(b []int16) []byte

func Int32Slice2byte added in v1.1.0

func Int32Slice2byte(b []int32) []byte

func Int64Slice2byte added in v1.1.0

func Int64Slice2byte(b []int64) []byte

func IntLimit added in v1.0.0

func IntLimit(min, max int, v int) int

func IntersectSortedSliceInt added in v1.4.0

func IntersectSortedSliceInt(slice1, slice2 []int) []int

func IsHot added in v1.4.0

func IsHot(tier uint64) bool

func IsInternalDatabase added in v1.5.0

func IsInternalDatabase(dbName string) bool

IsInternalDatabase returns true if the database is "_internal".

func IsObjectNil

func IsObjectNil(obj interface{}) bool

func Max added in v1.4.0

func Max[T NumberInt](x, y T) T

func MaxUint32 added in v1.1.0

func MaxUint32(x, y uint32) uint32

func Median added in v1.5.0

func Median[T NumberOnly](data []T) (float64, error)

Median calculates the median value of a numeric slice. It returns the median as a float64 and an error if the input slice is empty.

Note: This implementation uses the QuickSelect algorithm, which modifies the order of elements in the input slice during execution (through in-place partitioning). The original element positions will not be preserved.

The median is defined as: - For an odd-length slice: the middle element when the slice is sorted. - For an even-length slice: the average of the two middle elements when sorted.

QuickSelect is used here for efficient median calculation (average O(n) time complexity) without full sorting, making it suitable for large datasets.

func MemorySet added in v1.1.0

func MemorySet(buf []byte, val byte)

func Min added in v1.1.0

func Min(x, y int) int

func MinUint32 added in v1.2.0

func MinUint32(x, y uint32) uint32

func MustClose

func MustClose(obj io.Closer)

func MustRun added in v1.3.0

func MustRun(fn func() error)

func NumberOfTrailingZeros added in v1.1.0

func NumberOfTrailingZeros(num uint64) int

func OpenPprofServer added in v1.3.0

func OpenPprofServer(host, port string)

func PaddingZeroBuffer added in v1.3.0

func PaddingZeroBuffer(out []byte, size int) []byte

func Quantile added in v1.5.0

func Quantile[T NumberOnly](data []T, q float64) (float64, error)

Quantile computes the empirical quantile of a dataset using linear interpolation, consistent with the behavior of numpy.quantile (method="linear").

Note: This implementation uses the QuickSelect algorithm, which modifies the order of elements in the input slice during execution (through in-place partitioning). The original element positions will not be preserved.

func Search(begin, n int, f func(int) bool) int

func SetLogger

func SetLogger(lg *zap.Logger)

func SetTopoManagerUrl added in v1.5.0

func SetTopoManagerUrl(topoManagerUrl string)

func SliceSplitFunc added in v1.4.0

func SliceSplitFunc[E any](s []E, filter func(*E) bool) ([]E, []E)

func Str2bytes added in v1.1.0

func Str2bytes(s string) []byte

func TickerRun added in v1.4.0

func TickerRun(d time.Duration, stopSignal <-chan struct{}, onTick func(), onStop func())

func TimeCost added in v1.0.0

func TimeCost(option string) func()

func TrimMean added in v1.5.0

func TrimMean[T NumberOnly](data []T, proportionToCut float64) (float64, error)

TrimMean calculates the trimmed mean of a numeric slice by removing a specified proportion of elements from both the lower and upper ends, then averaging the remaining elements.

Note: This implementation uses the QuickSelect algorithm, which modifies the order of elements in the input slice during execution (through in-place partitioning). The original element positions will not be preserved.

func Uint16Slice2byte added in v1.1.0

func Uint16Slice2byte(b []uint16) []byte

func Uint32Slice2byte added in v1.1.0

func Uint32Slice2byte(b []uint32) []byte

func Uint64Slice2byte added in v1.1.0

func Uint64Slice2byte(b []uint64) []byte

func Uint64ToFloat64 added in v1.1.0

func Uint64ToFloat64(v uint64) float64

func UnionSortedSliceInt added in v1.4.0

func UnionSortedSliceInt(slice1, slice2 []int) []int

func WaitTimeOut added in v1.5.0

func WaitTimeOut(wait func(), done func(), timeout time.Duration)

Types

type BasicType added in v1.3.0

type BasicType interface {
	int64 | float64 | bool | string
}

type Client added in v1.5.0

type Client struct {
	Conf Config
}

func GetClientConf added in v1.5.0

func GetClientConf() *Client

func (*Client) PushURL added in v1.5.0

func (c *Client) PushURL(param Param, startTime, endTime string) (string, error)

func (*Client) SendGetRequest added in v1.5.0

func (c *Client) SendGetRequest(httpClient *http.Client, param Param, startTime string, endTime string) (string, error)

type ConcurrentRunner added in v1.4.0

type ConcurrentRunner[T any] struct {
	// contains filtered or unexported fields
}

func NewConcurrentRunner added in v1.4.0

func NewConcurrentRunner[T any](queues []*Queue[T], processors []Processor) *ConcurrentRunner[T]

func (*ConcurrentRunner[T]) Close added in v1.4.0

func (runner *ConcurrentRunner[T]) Close()

Close called after Stop

func (*ConcurrentRunner[T]) Schedule added in v1.4.0

func (runner *ConcurrentRunner[T]) Schedule(hash uint64, v *T)

func (*ConcurrentRunner[T]) Size added in v1.4.0

func (runner *ConcurrentRunner[T]) Size() int

func (*ConcurrentRunner[T]) Stop added in v1.4.0

func (runner *ConcurrentRunner[T]) Stop()

type Config added in v1.5.0

type Config struct {
	Path string
}

type ExceptBool added in v1.3.0

type ExceptBool interface {
	int64 | float64 | string
}

type ExceptString added in v1.3.0

type ExceptString interface {
	int64 | float64 | bool
}

type Item added in v1.5.0

type Item struct {
	Name      string
	Key       string
	TagValue  string
	SeriesKey string
	Tsid      uint64
}

type NumberInt added in v1.4.0

type NumberInt interface {
	int | int8 | int32 | int64 | uint8 | uint32 | uint64
}

type NumberOnly added in v1.3.0

type NumberOnly interface {
	int64 | float64
}

type Param added in v1.5.0

type Param struct {
	ParamName  string
	ParamValue string
}

type Processor added in v1.4.0

type Processor interface {
	Run()

	// Stop called before Close
	Stop()
	Close()
}

type Queue added in v1.4.0

type Queue[T any] struct {
	// contains filtered or unexported fields
}

func NewQueue added in v1.4.0

func NewQueue[T any](size int) *Queue[T]

func (*Queue[T]) Close added in v1.4.0

func (q *Queue[T]) Close()

func (*Queue[T]) Pop added in v1.4.0

func (q *Queue[T]) Pop() (*T, bool)

func (*Queue[T]) Push added in v1.4.0

func (q *Queue[T]) Push(v *T)

type Reference added in v1.4.0

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

func (*Reference) Ref added in v1.4.0

func (r *Reference) Ref()

func (*Reference) Unref added in v1.4.0

func (r *Reference) Unref()

func (*Reference) Wait added in v1.4.0

func (r *Reference) Wait()

type Signal added in v1.2.0

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

func NewSignal added in v1.2.0

func NewSignal() *Signal

func (*Signal) C added in v1.2.0

func (s *Signal) C() chan struct{}

func (*Signal) Close added in v1.2.0

func (s *Signal) Close()

func (*Signal) CloseOnce added in v1.4.0

func (s *Signal) CloseOnce(onClose func())

func (*Signal) Opening added in v1.2.0

func (s *Signal) Opening() bool

func (*Signal) ReOpen added in v1.2.0

func (s *Signal) ReOpen()

type SyncMap added in v1.5.0

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewSyncMap added in v1.5.0

func NewSyncMap[K comparable, V any]() *SyncMap[K, V]

func (*SyncMap[K, V]) Len added in v1.5.0

func (m *SyncMap[K, V]) Len() int

func (*SyncMap[K, V]) Load added in v1.5.0

func (m *SyncMap[K, V]) Load(k K) (V, bool)

func (*SyncMap[K, V]) LoadOrStore added in v1.5.0

func (m *SyncMap[K, V]) LoadOrStore(k K, creator func() V) (V, bool)

func (*SyncMap[K, V]) Range added in v1.5.0

func (m *SyncMap[K, V]) Range(fn func(K, V))

func (*SyncMap[K, V]) Remove added in v1.5.0

func (m *SyncMap[K, V]) Remove(k K)

func (*SyncMap[K, V]) Store added in v1.5.0

func (m *SyncMap[K, V]) Store(k K, v V)

type TimeRange added in v1.1.0

type TimeRange struct {
	Min, Max int64
}

func (TimeRange) Contains added in v1.3.0

func (t TimeRange) Contains(min, max int64) bool

func (TimeRange) Overlaps added in v1.1.0

func (t TimeRange) Overlaps(min, max int64) bool

type TimerPool added in v1.1.0

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

func NewTimePool added in v1.1.0

func NewTimePool() *TimerPool

func (*TimerPool) GetTimer added in v1.1.0

func (p *TimerPool) GetTimer(timeout time.Duration) *time.Timer

func (*TimerPool) PutTimer added in v1.1.0

func (p *TimerPool) PutTimer(timer *time.Timer)

Directories

Path Synopsis
lifted
bytebufferpool
Package bytebufferpool implements a pool of byte buffers with anti-fragmentation protection.
Package bytebufferpool implements a pool of byte buffers with anti-fragmentation protection.
encoding/simple8b
Package simple8b implements the 64bit integer encoding algoritm as published by Ann and Moffat in "Index compression using 64-bit words", Softw.
Package simple8b implements the 64bit integer encoding algoritm as published by Ann and Moffat in "Index compression using 64-bit words", Softw.
go-bitstream
Package bitstream is a simple wrapper around a io.Reader and io.Writer to provide bit-level access to the stream.
Package bitstream is a simple wrapper around a io.Reader and io.Writer to provide bit-level access to the stream.
hashicorp/serf/testutil/retry
Package retry provides support for repeating operations in tests.
Package retry provides support for repeating operations in tests.

Jump to

Keyboard shortcuts

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