multipriq

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: ISC Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiPriorityQueue

type MultiPriorityQueue struct {
	// contains filtered or unexported fields
}

MultiPriorityQueue is a probabilistic multi-priority queue: elements are pushed with a priority number (from 0 to 4) and are popped following a distribution that ensures elements from all priorities are (eventually) popped while preferring to pop elements with lower priority number.

The distribution is empirically determined, but with a full queue, the popping rate approaches the following:

Priority   Rate of Pop
    0         50.10%
    1         37.50%
    2          9.30%
    3          2.40%
    4          0.70%

The empty value is a valid MultiPriorityQueue. This structure is not safe for concurrent access.

func (*MultiPriorityQueue) Len

func (q *MultiPriorityQueue) Len() int

Len returns the number of items in the queue.

func (*MultiPriorityQueue) Peek

func (q *MultiPriorityQueue) Peek() interface{}

Peek returns the next value of the queue (but does not remove it from the queue).

func (*MultiPriorityQueue) Pop

func (q *MultiPriorityQueue) Pop() interface{}

Pop returns the next value to be removed from the queue and removes it.

Returns a nil interface when the queue is empty.

func (*MultiPriorityQueue) Push

func (q *MultiPriorityQueue) Push(v interface{}, pri uint)

Push the given value to the queue, using the specified priority number.

This function panics if pri is >= 5.

Jump to

Keyboard shortcuts

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