common

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DedupStringArray

func DedupStringArray(arr []string) []string

func ParseTime

func ParseTime(input string) (time.Time, error)

func SameStringSet

func SameStringSet(a, b []string) bool

SameStringSet checks if the set of elements are same or not.

func SortForAutocomplete

func SortForAutocomplete(input string, elements []string) []string

Types

type ConcurrentCounter

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

A thread-safe counter data structure

func NewConcurrentCounter

func NewConcurrentCounter(shardingMap *ShardingMap[int]) *ConcurrentCounter

func NewDefaultConcurrentCounter

func NewDefaultConcurrentCounter(shardingProvider MapShardingProvider) *ConcurrentCounter

func (*ConcurrentCounter) Get

func (c *ConcurrentCounter) Get(key string) int

func (*ConcurrentCounter) Incr

func (c *ConcurrentCounter) Incr(key string) int

type MapShardingProvider

type MapShardingProvider interface {
	// GetMaxShardCount returns the maximum count of shards. This must be constant value.
	GetMaxShardCount() int
	// GetShard returns the index of shard mapping to the given key. The index must be less than the returned value of GetMaxShardCount()
	GetShard(key string) int
}

MapShardingProvider interface defines how keys are mapped to specific shard.

type ShardingMap

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

ShardingMap provides locks by shards in a large map. This prevents lock entire map to access single element in a map.

func NewShardingMap

func NewShardingMap[T any](shardingProvider MapShardingProvider) *ShardingMap[T]

func (*ShardingMap[T]) AcquireShard

func (m *ShardingMap[T]) AcquireShard(key string) map[string]T

func (*ShardingMap[T]) AcquireShardReadonly

func (m *ShardingMap[T]) AcquireShardReadonly(key string) map[string]T

func (*ShardingMap[T]) AllKeys

func (m *ShardingMap[T]) AllKeys() (result []string)

func (*ShardingMap[T]) ReleaseShard

func (m *ShardingMap[T]) ReleaseShard(key string)

func (*ShardingMap[T]) ReleaseShardReadonly

func (m *ShardingMap[T]) ReleaseShardReadonly(key string)

type SuffixShardingProvider

type SuffixShardingProvider struct {
	ShardCount int
	// contains filtered or unexported fields
}

func NewSuffixShardingProvider

func NewSuffixShardingProvider(shardCount int, suffixLength int) *SuffixShardingProvider

func (*SuffixShardingProvider) GetMaxShardCount

func (h *SuffixShardingProvider) GetMaxShardCount() int

GetMaxShardCount implements MapShardingProvider.

func (*SuffixShardingProvider) GetShard

func (h *SuffixShardingProvider) GetShard(key string) int

GetShard implements MapShardingProvider.

type TimeSeries added in v0.56.2

type TimeSeries[V comparable] struct {
	Entries []TimeSeriesEntry[V]
}

TimeSeries tracks the value of a single variable over time. It is useful for cases where a value can change at different points in time.

func NewTimeSeries added in v0.56.2

func NewTimeSeries[V comparable]() *TimeSeries[V]

NewTimeSeries creates a new TimeSeries.

func (*TimeSeries[V]) Get added in v0.56.2

func (s *TimeSeries[V]) Get(t time.Time) (V, bool)

Get returns the value associated at time t. It tries to find the value active at t (using GetLastBeforeOrEqual). If no such entry exists (t is before all entries), it falls back to the earliest value seen (GetFirstAfterOrEqual).

func (*TimeSeries[V]) GetFirstAfterOrEqual added in v0.56.2

func (s *TimeSeries[V]) GetFirstAfterOrEqual(t time.Time) (V, bool)

GetFirstAfterOrEqual returns the value of the first entry whose timestamp is >= t.

func (*TimeSeries[V]) GetLastBeforeOrEqual added in v0.56.2

func (s *TimeSeries[V]) GetLastBeforeOrEqual(t time.Time) (V, bool)

GetLastBeforeOrEqual returns the value of the last entry whose timestamp is <= t.

func (*TimeSeries[V]) Set added in v0.56.2

func (s *TimeSeries[V]) Set(t time.Time, val V)

Set records that the value is associated starting from time t. It preserves chronological order using binary search insertion.

type TimeSeriesEntry added in v0.56.2

type TimeSeriesEntry[V comparable] struct {
	T   time.Time
	Val V
}

TimeSeriesEntry represents a value associated with a specific timestamp.

Directories

Path Synopsis
Package typeddict provides a generic, concurrent, type-safe dictionary.
Package typeddict provides a generic, concurrent, type-safe dictionary.

Jump to

Keyboard shortcuts

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