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]) 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 ¶
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.