containers

package
v0.4.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package containers provides helper containers for qruntime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PriorityQueue

type PriorityQueue[T comparable] struct {
	// contains filtered or unexported fields
}

PriorityQueue keeps a priority queue of items with backoff (release after).

PriorityQueue deduplicates by item (T).

func (*PriorityQueue[T]) Len

func (queue *PriorityQueue[T]) Len() int

Len returns the number of items in the queue.

func (*PriorityQueue[T]) Peek

func (queue *PriorityQueue[T]) Peek(now time.Time) (item optional.Optional[T], nextDelay time.Duration)

Peek returns the top item from the queue if it is ready to be released at now.

If Peek returns optional.None, it also returns delay to get the next item from the queue. If there are no items in the queue, Peek returns optional.None and zero delay.

func (*PriorityQueue[T]) Pop

func (queue *PriorityQueue[T]) Pop()

Pop removes the top item from the queue.

Pop should only be called if Peek returned optional.Some.

func (*PriorityQueue[T]) Push

func (queue *PriorityQueue[T]) Push(item T, releaseAfter time.Time) bool

Push item to the queue with releaseAfter time.

If the item is not in the queue, it will be added. If the item is in the queue, and releaseAfter is greater than the existing releaseAfter, it will be re-added in the new position.

Push returns true if the item was added, and false if the existing item in the queue was updated (or skipped).

type SliceSet

type SliceSet[T comparable] struct {
	// contains filtered or unexported fields
}

SliceSet is a set implementation based on slices (for small number of items).

func (*SliceSet[T]) Add

func (set *SliceSet[T]) Add(item T) bool

Add item to the set.

func (*SliceSet[T]) Contains

func (set *SliceSet[T]) Contains(item T) bool

Contains returns true if the set contains the item.

func (*SliceSet[T]) Len

func (set *SliceSet[T]) Len() int

Len returns the number of items in the set.

func (*SliceSet[T]) Remove

func (set *SliceSet[T]) Remove(item T) (found bool)

Remove item from the set.

Jump to

Keyboard shortcuts

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