lossy

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Buffer is a circular ring buffer stores the elements being transferred by the producers to the consumer. The monotonically increasing count of reads and writes allow indexing sequentially to the next element location based upon a power-of-two sizing.

The producers race to read the counts, check if there is available capacity, and if so then try once to CAS to the next write count. If the increment is successful then the producer lazily publishes the element. The producer does not retry or block when unsuccessful due to a failed CAS or the buffer being full.

The consumer reads the counts and takes the available elements. The clearing of the elements and the next read count are lazily set.

This implementation is striped to further increase concurrency.

func New

func New[K comparable, V any](nodeManager *node.Manager[K, V]) *Buffer[K, V]

New creates a new lossy Buffer.

func (*Buffer[K, V]) Add

func (b *Buffer[K, V]) Add(n node.Node[K, V]) *PolicyBuffers[K, V]

Add lazily publishes the item to the consumer.

item may be lost due to contention.

func (*Buffer[K, V]) Clear

func (b *Buffer[K, V]) Clear()

Clear clears the lossy Buffer and returns it to the default state.

func (*Buffer[K, V]) Free

func (b *Buffer[K, V]) Free()

Free returns the processed buffer back and also clears it.

type PolicyBuffers

type PolicyBuffers[K comparable, V any] struct {
	Returned []node.Node[K, V]
}

PolicyBuffers is the set of buffers returned by the lossy buffer.

Jump to

Keyboard shortcuts

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