Module Data.Queue

An implementation of double-ended queues supporting access at both ends in constant amortized time.

Author: Bernd Brassel, Olaf Chitil, Michael Hanus, Sebastian Fischer, Bjoern Peemoeller

Version: December 2018

Summary of exported operations:

empty :: Queue a  Deterministic 
The empty queue.
cons :: a -> Queue a -> Queue a  Deterministic 
Inserts an element at the front of the queue.
snoc :: a -> Queue a -> Queue a  Deterministic 
Inserts an element at the end of the queue.
isEmpty :: Queue a -> Bool  Deterministic 
Is the queue empty?
deqLength :: Queue a -> Int  Deterministic 
Returns the number of elements in the queue.
deqHead :: Queue a -> a  Deterministic 
The first element of the queue.
deqTail :: Queue a -> Queue a  Deterministic 
Removes an element at the front of the queue.
deqLast :: Queue a -> a  Deterministic 
The last element of the queue.
deqInit :: Queue a -> Queue a  Deterministic 
Removes an element at the end of the queue.
deqReverse :: Queue a -> Queue a  Deterministic 
Reverses a double ended queue.
rotate :: Queue a -> Queue a  Deterministic 
Moves the first element to the end of the queue.
matchHead :: Queue a -> Maybe (a,Queue a)  Deterministic 
Matches the front of a queue.
matchLast :: Queue a -> Maybe (a,Queue a)  Deterministic 
Matches the end of a queue.
listToDeq :: [a] -> Queue a  Deterministic 
Transforms a list to a double ended queue.
deqToList :: Queue a -> [a]  Deterministic 
Transforms a double ended queue to a list.

Exported datatypes:


Queue

The datatype of a queue.

Constructors:


Exported operations:

empty :: Queue a  Deterministic 

The empty queue.

Further infos:
  • solution complete, i.e., able to compute all solutions

cons :: a -> Queue a -> Queue a  Deterministic 

Inserts an element at the front of the queue.

snoc :: a -> Queue a -> Queue a  Deterministic 

Inserts an element at the end of the queue.

isEmpty :: Queue a -> Bool  Deterministic 

Is the queue empty?

deqLength :: Queue a -> Int  Deterministic 

Returns the number of elements in the queue.

deqHead :: Queue a -> a  Deterministic 

The first element of the queue.

deqTail :: Queue a -> Queue a  Deterministic 

Removes an element at the front of the queue.

deqLast :: Queue a -> a  Deterministic 

The last element of the queue.

deqInit :: Queue a -> Queue a  Deterministic 

Removes an element at the end of the queue.

deqReverse :: Queue a -> Queue a  Deterministic 

Reverses a double ended queue.

Further infos:
  • solution complete, i.e., able to compute all solutions

rotate :: Queue a -> Queue a  Deterministic 

Moves the first element to the end of the queue.

matchHead :: Queue a -> Maybe (a,Queue a)  Deterministic 

Matches the front of a queue. matchHead q is equivalent to if isEmpty q then Nothing else Just (deqHead q, deqTail q) but more efficient.

matchLast :: Queue a -> Maybe (a,Queue a)  Deterministic 

Matches the end of a queue. matchLast q is equivalent to if isEmpty q then Nothing else Just (deqLast q,deqInit q) but more efficient.

listToDeq :: [a] -> Queue a  Deterministic 

Transforms a list to a double ended queue.

deqToList :: Queue a -> [a]  Deterministic 

Transforms a double ended queue to a list.