Documentation
¶
Overview ¶
Package efficiency offers utilities for generating read-only channels, merging and splitting streams, concurrent processing of channel items, and partitioning key-value stores using shards for scalability and performance.
Index ¶
- func Generate[T any](in ...T) <-chan T
- func Merge[T any](in ...<-chan T) chan T
- func Process[IN, OUT any](in <-chan IN, fn service.Function[IN, OUT]) (<-chan OUT, <-chan error)
- func Split[T any](in <-chan T, num int) []<-chan T
- func WithCompression(next http.Handler) http.Handler
- type Shard
- type Sharding
- type SparseSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
func Generate[T any](in ...T) <-chan T
Generate takes a variadic input of any type T and returns a read-only channel of type T. It sends each input value into the returned channel in a separate goroutine.
func Merge ¶
func Merge[T any](in ...<-chan T) chan T
Merge combines multiple input channels into a single output channel. It starts a goroutine for each input channel to forward its values to the output channel. Once all input channels are processed, the output channel is closed.
func Process ¶
Process concurrently processes items from the input channel using the provided function `fn`. It spawns a number of worker goroutines equal to the number of available CPU cores.
Types ¶
type Shard ¶
type Shard[K comparable, V any] struct { // contains filtered or unexported fields }
Shard represents a single partition of a sharded key-value store. It holds a map of keys (of type K) to values (of type V), and a mutex for thread-safety.
type Sharding ¶
type Sharding[K comparable, V any] []Shard[K, V]
Sharding is a collection of Shard objects, each representing a separate partition of the key-value store. This allows for distributing keys across multiple shards.
func NewSharding ¶
func NewSharding[K comparable, V any](num int) Sharding[K, V]
NewSharding creates an array of Shard objects with the given number of shards.
func (Sharding[K, V]) Delete ¶
func (a Sharding[K, V]) Delete(key K)
Delete removes a key-value pair from the appropriate shard.
type SparseSet ¶ added in v0.1.62
type SparseSet[T comparable] struct { Dense []T Size int Sparse []int }
SparseSet is a data structure that provides efficient storage and retrieval of elements.
func NewSparseSet ¶ added in v0.1.62
func NewSparseSet[T comparable](initialSize int) *SparseSet[T]
NewSparseSet creates a new SparseSet with the given initial Size.
func (*SparseSet[T]) Densed ¶ added in v0.1.65
func (a *SparseSet[T]) Densed() []T
Densed returns the Dense representation of the SparseSet.