This module implements (double ended) FIFO queues in an efficient manner.
All functions fail with reason
Some functions, where noted, fail with reason
The data representing a queue as used by this module should be regarded as opaque by other modules. Any code assuming knowledge of the format is running on thin ice.
All operations has an amortized O(1) running time, except
Queues are double ended. The mental picture of a queue is a line of people (items) waiting for their turn. The queue front is the end with the item that has waited the longest. The queue rear is the end an item enters when it starts to wait. If instead using the mental picture of a list, the front is called head and the rear is called tail.
Entering at the front and exiting at the rear are reverse operations on the queue.
The module has several sets of interface functions. The "Original API", the "Extended API" and the "Okasaki API".
The "Original API" and the "Extended API" both use the mental picture of a waiting line of items. Both also have reverse operations suffixed "_r".
The "Original API" item removal functions return compound terms with both the removed item and the resulting queue. The "Extended API" contain alternative functions that build less garbage as well as functions for just inspecting the queue ends. Also the "Okasaki API" functions build less garbage.
The "Okasaki API" is inspired by "Purely Functional Data structures" by Chris Okasaki. It regards queues as lists. The API is by many regarded as strange and avoidable. For example many reverse operations have lexically reversed names, some with more readable but perhaps less understandable aliases.
As returned by
Returns an empty queue.
Tests if
Tests if
Calculates and returns the length of queue
Inserts
Inserts
Removes the item at the front of queue
Removes the item at the rear of the queue
Returns a queue containing the items in
Returns a list of the items in the queue in the same order; the front item of the queue will become the head of the list.
Returns a queue
Splits
Returns a queue
Returns a queue
If
So,
Returns
Returns
Fails with reason
Returns
Fails with reason
Returns a queue
Fails with reason
Returns a queue
Fails with reason
Returns the tuple
Returns the tuple
Inserts
Returns
Fails with reason
Returns a queue
Fails with reason
Inserts
Returns the tail item of queue
Fails with reason
Returns a queue
Fails with reason
The name