library(queues)
This module provides an implementation of queues, where you can
Exported predicates:
empty_queue(
?Queue)
singleton_queue(
?X,
?Queue)
portray_queue(
+Queue)
is_queue(
Queue)
has been established,
as by user:portray(Q) :- is_queue(Q), !, portray_queue(Q)
.
it is also meant to work however it is called.
is_queue(
+Queue)
queue_length(
Queue, _)
.
queue_head(
+Queue,
-Head)
queue_tail(
?Queue,
?Tail)
queue_cons(
?Head,
?Tail,
?Queue)
queue_cons(+Head, +Q0, -Q) adds Head to Q0 giving Q queue_cons(-Head, -Q, +Q0) removes Head from Q0 giving Q
queue_last(
?Last,
?Queue)
queue_last(
+Fore,
+Last,
-Queue)
queue_cons/3
, and it side-effects Fore,
again unlike queue_cons/3
.
append_queue(
?List,
?Queue0,
?Queue)
append_queue([a,b,c], Queue[d,e], Queue[a,b,c,d,e])
. Use
append_queue([+X1,...,+Xn], +Q0, -Q) to add X1,...,Xn to Q0 giving Q append_queue([-X1,...,-Xn], -Q, +Q0) to take X1...Xn from Q0 giving Q
The cost is O(n) and the operation is pure.
queue_append(
+Queue0,
+List,
-Queue)
append_queue(Queue[a,b,c], [d,e], Queue[a,b,c,d,e])
.
This is like queue_last/3
; it side-effects Queue0.
list_queue(
?List,
?Queue)
list_queue/2
and queue_list/2
are the same except for argument order.
queue_list(
?Queue,
?List)
queue_list/2
and list_queue/2
are the same except for argument order.
queue_length(
?Queue,
?Length)
queue_member(
?Element,
+Queue)
queue_member/2
because it is prepared to enumerate Elements.
queue_memberchk(
+Element,
+Queue)
map_queue(
:Pred,
+Queue[X1,...,Xn])
map_queue(
:Pred,
+Queue[X1,...,Xn],
?Queue[Y1,...,Yn])
map_queue_list(
:Pred,
?Queue[X1,...,Xn],
?[Y1,...,Yn])
map_list_queue(
:Pred,
?[X1,...,Xn],
?Queue[Y1,...,Yn])
some_queue(
:Pred,
+Queue[X1,...,Xn])
somechk_queue/2
is to some_queue/2
as memberchk/2
is to member/2
; you are more likely to want somechk_queue/2
.
This acts on backtracking like member/2
; Queue should be proper.
some_queue(
:Pred,
+Queue[X1,...,Xn],
?Queue[Y1,...,Yn])
somechk_queue(
:Pred,
+Queue[X1,...,Xn])
memberchk/2
).
somechk_queue(
:Pred,
+Queue[X1,...,Xn],
?Queue[Y1,...,Yn])
memberchk/2
).