Version: 5.0.1
17 Imperative Queues
(require unstable/queue) |
This library is unstable;
compatibility will not be maintained.
See Unstable for more information.
This module provides a simple mutable queue representation, first-in/first-out only. Operations on queues mutate it in a thread-unsafe way.
(make-queue) → queue/c |
Produces an empty queue.
Adds an element to the back of a queue.
(dequeue! q) → any/c |
q : nonempty-queue/c |
Removes an element from the front of a nonempty queue, and returns that
element.
Examples: | ||
| ||
> (enqueue! q 1) | ||
> (dequeue! q) | ||
1 | ||
> (enqueue! q 2) | ||
> (enqueue! q 3) | ||
> (dequeue! q) | ||
2 | ||
> (dequeue! q) | ||
3 |
(queue-empty? q) → boolean? |
q : queue/c |
Recognizes whether a queue is empty or not.
Examples: | ||
| ||
> (queue-empty? q) | ||
#t | ||
> (enqueue! q 1) | ||
> (queue-empty? q) | ||
#f | ||
> (dequeue! q) | ||
1 | ||
> (queue-empty? q) | ||
#t |
This predicate recognizes queues.
Examples: |
> (queue? (make-queue)) |
#t |
> (queue? 'not-a-queue) |
#f |
These contracts recognize queues; the latter requires the queue to
contain at least one value.