# Module pqueue

- Description
- Data Types
- Function Index
- Function Details

### Static Priority Queue.

This priority queue implementation depends on a static number of priorities (-20 (high) to 20 (low)) so that tuple access times can be exploited for quick in/out priority queue operations.

Copyright © 2011-2020 Michael Truog

Version: 2.0.1 Nov 26 2020 14:55:34 ------------------------------------------------------------------------

Authors: Michael Truog (`mjtruog at protonmail dot com`).

## Description

### Static Priority Queue.

This priority queue implementation depends on a static number of priorities (-20 (high) to 20 (low)) so that tuple access times can be exploited for quick in/out priority queue operations. This implementation was created to avoid the slowness within the priority queue used by both RabbitMQ and Riak (https://github.com/basho/riak_core/blob/master/src/priority_queue.erl).

## Data Types

### pqueue()

`pqueue() = {integer(), {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, queue:queue(), {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}} | {empty, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, queue:queue(), {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}, {queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue(), queue:queue()}}`

## Function Index

in/2 | #### Append an item to the tail of the 0 priority queue. O(1).
in/3 | #### Append an item to the tail of a specific priority queue. O(1).
is_empty/1 | #### Check if the priority queue is empty. O(1).
is_queue/1 | #### Check if the priority queue type is as expected. O(1).
join/2 | #### Join two priority queues. O(N).
len/1 | #### Determine the length of a priority queue. O(N).
new/0 | #### Create a new priority queue. O(1).
out/1 | #### Take an item from the head of the priority queue. O(1) amortized, O(N) worst case.
out/2 | #### Take an item of a specific priority from the head of the queue. O(1) amortized, O(N) worst case.
pout/1 | #### Take an item from the head of the priority queue. Includes the priority in the return value.
test/0 | #### Regression test. .
to_list/1 | #### Convert the priority queue to a list. O(N).

## Function Details

### in/2

`in(X::term(), Q::pqueue()) -> pqueue()`

#### Append an item to the tail of the 0 priority queue.

O(1)

### in/3

`in(X::term(), P::integer(), Q::pqueue()) -> pqueue()`

#### Append an item to the tail of a specific priority queue.

O(1)

### is_empty/1

`is_empty(X1::pqueue()) -> true | false`

#### Check if the priority queue is empty.

O(1)

### is_queue/1

`is_queue(X1::pqueue()) -> true | false`

#### Check if the priority queue type is as expected.

O(1)

### join/2

`join(X1::pqueue(), X2::pqueue()) -> pqueue()`

#### Join two priority queues.

O(N)

### len/1

`len(X1::pqueue()) -> non_neg_integer()`

#### Determine the length of a priority queue.

O(N)

### new/0

`new() -> pqueue()`

#### Create a new priority queue.

O(1)

### out/1

`out(Q::pqueue()) -> {{value, term()}, pqueue()} | {empty, pqueue()}`

#### Take an item from the head of the priority queue.

O(1) amortized, O(N) worst case

### out/2

`out(P::integer(), Q::pqueue()) -> {{value, term()}, pqueue()} | {empty, pqueue()}`

#### Take an item of a specific priority from the head of the queue.

O(1) amortized, O(N) worst case

### pout/1

`pout(Q::pqueue()) -> {{value, term(), integer()}, pqueue()} | {empty, pqueue()}`

#### Take an item from the head of the priority queue.

Includes the priority in the return value. O(1) amortized, O(N) worst case

### test/0

`test() -> any()`

#### Regression test.

### to_list/1

`to_list(X1::pqueue()) -> [term()]`

#### Convert the priority queue to a list.

O(N)

Generated by EDoc