rpq

package
v0.0.0-...-3f013c7 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package rpq implements a recurrent priority queue: a priority queue whose elements can be returned multiple times, up to a specified quota, prioritized according to how many times they have already been returned.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

A Queue is a recurrent priority queue of key-value pairs.

func New

func New[K comparable, V any](quota func() int) *Queue[K, V]

New initializes a new Queue. Quota describes the minimum number of times an item will be returned by Pop or PopN before it is removed from the Queue.

func (*Queue[K, V]) Len

func (q *Queue[K, V]) Len() int

Len returns the number of items in the Queue.

func (*Queue[K, V]) Pop

func (q *Queue[K, V]) Pop() V

Pop returns a value of the highest priority and removes it from the Queue if the number of times it has been returned is greater than or equal to the value returned by quota. Pop panics if the Queue is empty.

func (*Queue[K, V]) PopN

func (q *Queue[K, V]) PopN(n int) []V

PopN returns up to n distinct items of the highest priorities. If there are at least n items in the queue, PopN returns n of them, or else all of them. PopN removes any returned items from the Queue for which the number of times they have been returned is greater than or equal to the value returned by quota.

func (*Queue[K, V]) Upsert

func (q *Queue[K, V]) Upsert(key K, value V)

Upsert inserts a key-value pair into the Queue, or updates value if key is already present.

Jump to

Keyboard shortcuts

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