common

package
v0.0.0-...-9f7285a Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DedupStringArray

func DedupStringArray(arr []string) []string

func NewUUID

func NewUUID() string

NewUUID returns the random UUID in string

func ParseTime

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

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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