Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 Bib Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

4 Queues and Deques
 4.1 API
 4.2 Deques implemented using plain lists

4 Queues and Deques

4.1 API

4.1-1 IsQueue
‣ IsQueue( arg )( filter )

Returns: true or false

The category of queues.

4.1-2 IsDeque
‣ IsDeque( arg )( filter )

Returns: true or false

The category of deques.

4.1-3 PushBack
‣ PushBack( deque, object )( operation )

Add object to the back of deque.

4.1-4 PushFront
‣ PushFront( deque, object )( operation )

Add object to the front of deque.

4.1-5 PopBack
‣ PopBack( deque )( operation )

Returns: object

Remove an element from the back of deque and return it.

4.1-6 PopFront
‣ PopFront( deque )( operation )

Returns: object

Remove an element from the front of deque and return it.

For queues, this is just an alias for PushBack

4.1-7 Enqueue
‣ Enqueue( queue, object )( operation )

Add object to queue.

4.1-8 Dequeue
‣ Dequeue( queue )( operation )

Returns: object

Remove an object from the front of queue and return it.

4.1-9 Capacity
‣ Capacity( arg )( attribute )

Allocated storage capacity of queue.

4.1-10 Capacity
‣ Capacity( arg )( attribute )

Allocated storage capacity of deque.

4.1-11 Length
‣ Length( arg )( attribute )

Number of elements in queue.

4.1-12 Length
‣ Length( arg )( attribute )

Number of elements in deque.

4.2 Deques implemented using plain lists

datastructures implements deques using a circular buffer stored in a GAP a plain list, wrapped in a positional object (Reference: Positional Objects).

The five positions in such a deque Q have the following purpose

Global constants QHEAD, QTAIL, QCAPACITY, QFACTOR, and QDATA are bound to reflect the above.

When a push fills the deque, its capacity is resized by a factor of QFACTOR using PlistDequeExpand. A new empty plist is allocated and all current entries of the deque are copied into the new plist with the head entry at index 1.

The deque is empty if and only if head = tail and the entry that head and tail point to in the storage list is unbound.

4.2-1 PlistDeque
‣ PlistDeque( [capacity[, factor]] )( function )

Returns: a deque

Constructor for plist based deques. The optional argument capacity must be a positive integer and is the capacity of the created deque, and the optional argument factor must be a rational number greater than one which is the factor by which the storage of the deque is increased if it runs out of capacity when an object is put on the queue.

4.2-2 PlistDequePushFront
‣ PlistDequePushFront( deque, object )( function )

Push object to the front of deque.

4.2-3 PlistDequePushBack
‣ PlistDequePushBack( deque, object )( function )

Push object to the back of deque.

4.2-4 PlistDequePopFront
‣ PlistDequePopFront( deque )( function )

Returns: object or fail

Pop object from the front of deque and return it. If deque is empty, returns fail.

4.2-5 PlistDequePopBack
‣ PlistDequePopBack( deque )( function )

Returns: object or fail

Pop object from the back of deque and return it. If deque is empty, returns fail.

4.2-6 PlistDequePeekFront
‣ PlistDequePeekFront( deque )( function )

Returns: object or fail

Returns the object at the front deque without removing it. If deque is empty, returns fail.

4.2-7 PlistDequePeekBack
‣ PlistDequePeekBack( deque )( function )

Returns: object or fail

Returns the object at the back deque without removing it. If deque is empty, returns fail.

4.2-8 PlistDequeExpand
‣ PlistDequeExpand( deque )( function )

Helper function to expand the capacity of deque by the configured factor.

Queues are linear data structure that allow adding elements at the end of the queue, and removing elements from the front. A deque is a double-ended queue; a linear data structure that allows access to objects at both ends.

The API that objects that lie in IsQueue (4.1-1) and IsDeque (4.1-2) must implement the API set out below.

datastructures provides

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 Bib Ind

generated by GAPDoc2HTML