Documentation ¶
Overview ¶
Package mpsc provides an efficient implementation of a multi-producer, single-consumer lock-free queue.
The Push function is safe to call from multiple goroutines. The Pop and Empty APIs must only be called from a single, consumer goroutine.
Package singleflight provides a duplicate function call suppression mechanism.
Index ¶
- Constants
- Variables
- type CountMinSketch
- type DataBlock
- type Entry
- type Group
- type Hasher
- type List
- func (l *List[K, V]) Back() *Entry[K, V]
- func (l *List[K, V]) Contains(entry *Entry[K, V]) bool
- func (l *List[K, V]) Front() *Entry[K, V]
- func (l *List[K, V]) Len() int
- func (l *List[K, V]) MoveAfter(e, mark *Entry[K, V])
- func (l *List[K, V]) MoveBefore(e, mark *Entry[K, V])
- func (l *List[K, V]) MoveToBack(e *Entry[K, V])
- func (l *List[K, V]) MoveToFront(e *Entry[K, V])
- func (l *List[K, V]) Persist(writer io.Writer, blockEncoder *gob.Encoder, tp uint8) error
- func (l *List[K, V]) PopTail() *Entry[K, V]
- func (l *List[K, V]) PushBack(e *Entry[K, V]) *Entry[K, V]
- func (l *List[K, V]) PushFront(e *Entry[K, V]) *Entry[K, V]
- func (l *List[K, V]) Remove(e *Entry[K, V])
- func (l *List[K, V]) Reset()
- type Loaded
- type LoadingStore
- type MetaData
- type Metrics
- type NotFound
- type Pentry
- type Queue
- type ReadBufItem
- type RemoveReason
- type Result
- type SecondaryCache
- type SecondaryCacheItem
- type Serializer
- type Shard
- type Slru
- type Store
- func (s *Store[K, V]) Close()
- func (s *Store[K, V]) Delete(key K)
- func (s *Store[K, V]) DeleteWithSecondary(key K) error
- func (s *Store[K, V]) Get(key K) (V, bool)
- func (s *Store[K, V]) GetWithSecodary(key K) (value V, ok bool, err error)
- func (s *Store[K, V]) Len() int
- func (s *Store[K, V]) Persist(version uint64, writer io.Writer) error
- func (s *Store[K, V]) Range(f func(key K, value V) bool)
- func (s *Store[K, V]) Recover(version uint64, reader io.Reader) error
- func (s *Store[K, V]) Set(key K, value V, cost int64, ttl time.Duration) bool
- type StoreMeta
- type StringKey
- type TimerWheel
- type TinyLfu
- func (t *TinyLfu[K, V]) Access(item ReadBufItem[K, V])
- func (t *TinyLfu[K, V]) EvictEntries() []*Entry[K, V]
- func (t *TinyLfu[K, V]) Remove(entry *Entry[K, V])
- func (t *TinyLfu[K, V]) Set(entry *Entry[K, V]) *Entry[K, V]
- func (t *TinyLfu[K, V]) UpdateCost(entry *Entry[K, V], delta int64)
- func (t *TinyLfu[K, V]) UpdateThreshold()
- type WriteBufItem
Constants ¶
const ( NEW int8 = iota REMOVE UPDATE )
const ( LIST_PROBATION uint8 = 1 LIST_PROTECTED uint8 = 2 WHEEL_LIST uint8 = 3 )
const ( MAX_READ_BUFF_SIZE = 64 MIN_WRITE_BUFF_SIZE = 4 MAX_WRITE_BUFF_SIZE = 1024 )
const BlockBufferSize = 4 * 1024 * 1024
Variables ¶
var (
VersionMismatch = errors.New("version mismatch")
)
Functions ¶
This section is empty.
Types ¶
type CountMinSketch ¶
func NewCountMinSketch ¶
func NewCountMinSketch() *CountMinSketch
func (*CountMinSketch) Add ¶
func (s *CountMinSketch) Add(h uint64) bool
func (*CountMinSketch) EnsureCapacity ¶ added in v0.3.0
func (s *CountMinSketch) EnsureCapacity(size uint)
func (*CountMinSketch) Estimate ¶
func (s *CountMinSketch) Estimate(h uint64) uint
type DataBlock ¶ added in v0.2.6
type DataBlock[V any] struct { Type uint8 SecondaryType uint8 CheckSum uint64 Index uint64 // helper filed, usage depends on Type/SecondaryType Data []byte // contains filtered or unexported fields }
type Entry ¶
type Entry[K comparable, V any] struct { // contains filtered or unexported fields }
type Group ¶ added in v0.2.0
type Group[K comparable, V any] struct { // contains filtered or unexported fields }
Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.
func NewGroup ¶ added in v0.2.6
func NewGroup[K comparable, V any]() *Group[K, V]
func (*Group[K, V]) Do ¶ added in v0.2.0
Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. The return value shared indicates whether v was given to multiple callers.
type Hasher ¶
type Hasher[K comparable] struct { // contains filtered or unexported fields }
func NewHasher ¶
func NewHasher[K comparable](stringKeyFunc func(K) string) *Hasher[K]
type List ¶
type List[K comparable, V any] struct { // contains filtered or unexported fields }
List represents a doubly linked list. The zero value for List is an empty list ready to use.
func NewList ¶
func NewList[K comparable, V any](size uint, listType uint8) *List[K, V]
New returns an initialized list.
func (*List[K, V]) MoveAfter ¶
MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List[K, V]) MoveBefore ¶
MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List[K, V]) MoveToBack ¶
MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.
func (*List[K, V]) MoveToFront ¶
MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.
type LoadingStore ¶ added in v0.2.0
type LoadingStore[K comparable, V any] struct { *Store[K, V] // contains filtered or unexported fields }
func NewLoadingStore ¶ added in v0.2.0
func NewLoadingStore[K comparable, V any](store *Store[K, V]) *LoadingStore[K, V]
type MetaData ¶
type MetaData[K comparable, V any] struct { // contains filtered or unexported fields }
type Pentry ¶ added in v0.2.6
type Pentry[K comparable, V any] struct { Key K Value V Cost int64 Expire int64 Frequency int32 Removed bool }
entry for persistence
type Queue ¶
type Queue[V any] struct { // contains filtered or unexported fields }
func (*Queue[V]) Empty ¶
Empty returns true if the queue is empty
Empty must be called from a single, consumer goroutine
type ReadBufItem ¶
type ReadBufItem[K comparable, V any] struct { // contains filtered or unexported fields }
type RemoveReason ¶ added in v0.1.2
type RemoveReason uint8
const ( REMOVED RemoveReason = iota EVICTED EXPIRED )
type Result ¶ added in v0.2.0
type Result struct { Val interface{} Err error }
Result holds the results of Do, so they can be passed on a channel.
type SecondaryCache ¶ added in v0.3.0
type SecondaryCacheItem ¶ added in v0.3.0
type SecondaryCacheItem[K comparable, V any] struct { // contains filtered or unexported fields }
type Serializer ¶ added in v0.3.0
type Shard ¶
type Shard[K comparable, V any] struct { // contains filtered or unexported fields }
type Slru ¶
type Slru[K comparable, V any] struct { // contains filtered or unexported fields }
type Store ¶
type Store[K comparable, V any] struct { // contains filtered or unexported fields }
func NewStore ¶
func NewStore[K comparable, V any]( maxsize int64, doorkeeper bool, listener func(key K, value V, reason RemoveReason), cost func(v V) int64, secondaryCache SecondaryCache[K, V], workers int, probability float32, stringKeyFunc func(k K) string, ) *Store[K, V]
New returns a new data struct with the specified capacity
func (*Store[K, V]) DeleteWithSecondary ¶ added in v0.3.0
func (*Store[K, V]) GetWithSecodary ¶ added in v0.3.0
type StoreMeta ¶ added in v0.2.6
type StoreMeta struct { Version uint64 StartNano int64 Sketch *CountMinSketch }
type TimerWheel ¶
type TimerWheel[K comparable, V any] struct { // contains filtered or unexported fields }
func NewTimerWheel ¶
func NewTimerWheel[K comparable, V any](size uint) *TimerWheel[K, V]
type TinyLfu ¶
type TinyLfu[K comparable, V any] struct { // contains filtered or unexported fields }
func NewTinyLfu ¶
func NewTinyLfu[K comparable, V any](size uint, hasher *Hasher[K]) *TinyLfu[K, V]
func (*TinyLfu[K, V]) Access ¶
func (t *TinyLfu[K, V]) Access(item ReadBufItem[K, V])
func (*TinyLfu[K, V]) EvictEntries ¶
func (*TinyLfu[K, V]) UpdateCost ¶
func (*TinyLfu[K, V]) UpdateThreshold ¶
func (t *TinyLfu[K, V]) UpdateThreshold()
type WriteBufItem ¶
type WriteBufItem[K comparable, V any] struct { // contains filtered or unexported fields }