collections

package
v0.1.1-experimental.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[V any] struct {
	// contains filtered or unexported fields
}

Queue is a simple queue implementation that uses a map and two sequences. TODO: Check atomicity of write operations.

func NewQueue

func NewQueue[V any](
	schema *sdkcollections.SchemaBuilder, name string,
	valueCodec sdkcodec.ValueCodec[V],
) *Queue[V]

NewQueue creates a new queue with the provided prefix and name.

func (*Queue[V]) Container

func (q *Queue[V]) Container() sdkcollections.Map[uint64, V]

Container returns the underlying map container of the queue.

func (*Queue[V]) Len

func (q *Queue[V]) Len(ctx context.Context) (uint64, error)

Len returns the length of the queue.

func (*Queue[V]) Peek

func (q *Queue[V]) Peek(ctx context.Context) (V, error)

Peek wraps the peek method with a read lock.

func (*Queue[V]) PeekMulti

func (q *Queue[V]) PeekMulti(ctx context.Context, n uint64) ([]V, error)

PeekMulti returns the top n elements of the queue.

func (*Queue[V]) Pop

func (q *Queue[V]) Pop(ctx context.Context) (V, error)

Pop returns the top element of the queue and removes it from the queue.

func (*Queue[V]) PopMulti

func (q *Queue[V]) PopMulti(ctx context.Context, n uint64) ([]V, error)

PopMulti returns the top n elements of the queue and removes them from the queue.

func (*Queue[V]) Push

func (q *Queue[V]) Push(ctx context.Context, value V) error

Push adds a new element to the queue.

func (*Queue[V]) PushMulti

func (q *Queue[V]) PushMulti(ctx context.Context, values []V) error

PushMulti adds multiple new elements to the queue.

func (*Queue[V]) UnsafePeek

func (q *Queue[V]) UnsafePeek(ctx context.Context) (V, error)

UnsafePeek returns the top element of the queue without removing it. It is unsafe to call this method without acquiring the read lock.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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