Documentation
¶
Index ¶
- func DedupStringArray(arr []string) []string
- func ParseTime(input string) (time.Time, error)
- func SameStringSet(a, b []string) bool
- func SortForAutocomplete(input string, elements []string) []string
- type ConcurrentCounter
- type MapShardingProvider
- type ShardingMap
- type SuffixShardingProvider
- type TimeSeries
- type TimeSeriesEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DedupStringArray ¶
func SameStringSet ¶
SameStringSet checks if the set of elements are same or not.
func SortForAutocomplete ¶
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.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package typeddict provides a generic, concurrent, type-safe dictionary.
|
Package typeddict provides a generic, concurrent, type-safe dictionary. |