Deques
Factor handbook » The language » Collections

Prev:Enumerations
Next:Double-linked lists


The deques vocabulary implements the deque data structure which has constant-time insertion and removal of elements at both ends.

Deques must be instances of a mixin class:
deque


Deques must implement a protocol.

Querying the deque:
peek-front ( deque -- obj )

peek-back ( deque -- obj )

deque-empty? ( deque -- ? )

deque-member? ( value deque -- ? )


Adding and removing elements:
push-front* ( obj deque -- node )

push-back* ( obj deque -- node )

pop-front* ( deque -- )

pop-back* ( deque -- )

clear-deque ( deque -- )


Working with node objects output by push-front* and push-back*:
delete-node ( node deque -- )

node-value ( node -- value )


Utility operations built in terms of the above:
push-front ( obj deque -- )

push-all-front ( seq deque -- )

push-back ( obj deque -- )

push-all-back ( seq deque -- )

pop-front ( deque -- obj )

pop-back ( deque -- obj )

slurp-deque ( ... deque quot: ( ... obj -- ... ) -- ... )


When using a deque as a queue, the convention is to queue elements with push-front and deque them with pop-back.