Following queue structures implement and provide the functions empty?, enqueue, head, tail, queue and queue->list. All the queue structures are polymorphic.
A Queue is nothing but a FIFO data structure. A Banker’s Queue is a amortized queue obtained using Bankers method. It provides a amortized running time of O(1) for head , tail and enqueue operations. To obtain this amortized running time, the data structure uses the techniques, lazy evaluation and memoization. Banker’s Queue internally uses Streams for lazy evaluation. For Streams, see Streams
syntax
( Queue A)
- : #(struct:Queue
((Rec
g292706
(U (Pairof Positive-Byte g292706) (Promiseof g292706) Null))
Integer
(Listof Positive-Byte)
Integer))
#<Queue>
In the above example, the queue obtained will have 1 as its head element.
In the above example, (enqueue 10(queue 456)) enqueues 10 to the end of the queue and returns (queue 45610).
- : #(struct:Queue
((Rec
g292844
(U (Pairof Positive-Byte g292844) (Promiseof g292844) Null))
Integer
(Listof Positive-Byte)
Integer))
#<Queue>
tail: given queue is empty
In the above example, (tail (queue 456)), returns (queue 56).
procedure
( queue->list que)→(Queue A)
- : (Listof Positive-Byte)
'(10 2 34 4 15 6)
- : (Listof Integer)
'()
- : (Listof Positive-Index)
'(2 3 4 5 6 7)
- : (Listof Positive-Index)
'(1 4 9 16 25 36)
fold currently does not produce correct results when the given function is non-commutative.
- : Integer [more precisely: Nonnegative-Integer]
21
- : Integer [more precisely: Positive-Integer]
518400
- : (Listof Positive-Byte)
'(6)
- : (Listof Positive-Byte)
'(1 2 3 4)
- : (Listof Positive-Byte)
'(1 2 3 4 5)
- : (Listof Positive-Byte)
'(1 2 3 4 5)
- : (Listof Positive-Byte)
'(5 6)
- : (Listof Positive-Byte)
'(6)
- : Boolean
#f
- : Boolean
#f
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
procedure
( build-queue sizefunc)→(Queue A)
size:Naturalfunc:(Natural->A)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(0 1 4 9 16)
- : (Pairof
Positive-Byte
#(struct:Queue
((Rec
g293581
(U (Pairof Positive-Byte g293581) (Promiseof g293581) Null))
Integer
(Listof Positive-Byte)
Integer)))
'(1 . #<Queue>)
- : (Pairof
Integer
#(struct:Queue
((Rec g293604 (U (Pairof Integer g293604) (Promiseof g293604) Null))
Integer
(Listof Integer)
Integer)))
'(0 . #<Queue>)
head+tail: given queue is empty
A Queue is nothing but a FIFO data structure. A Physicist’s queue ia a Amortized queues obtained by Physicist’s method. Provides a amortized running time of O(1) for head , tail and enqueue operations. Physicists’s Queue uses lazy evaluation and memoization to get this amortized running time.
syntax
( Queue A)
- : #(struct:Queue
((Listof Integer)
(Boxof (U (-> (Listof Integer)) (Listof Integer)))
Integer
(Listof Integer)
Integer))
#<Queue>
In the above example, the queue obtained will have 1 as its head element
In the above example, enqueue adds the element 10 to (queue 123456) and returns (queue 12345610).
In the above example, (tail (queue 123456)), returns (queue 23456).
procedure
( queue->list que)→(Queue A)
- : (Listof Integer)
'(10 2 34 4 15 6)
- : (Listof Integer)
'()
- : (Listof Integer)
'(2 3 4 5 6 7)
- : (Listof Integer)
'(1 4 9 16 25 36)
fold currently does not produce correct results when the given function is non-commutative.
- : (Listof Integer)
'(6)
- : (Listof Integer)
'(1 2 3 4)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(5 6)
- : (Listof Integer)
'(6)
- : Boolean
#f
- : Boolean
#f
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
procedure
( build-queue sizefunc)→(Queue A)
size:Naturalfunc:(Natural->A)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(0 1 4 9 16)
- : (Pairof
Integer
#(struct:Queue
((Listof Integer)
(Boxof (U (-> (Listof Integer)) (Listof Integer)))
Integer
(Listof Integer)
Integer)))
'(1 . #<Queue>)
- : (Pairof
Integer
#(struct:Queue
((Listof Integer)
(Boxof (U (-> (Listof Integer)) (Listof Integer)))
Integer
(Listof Integer)
Integer)))
'(0 . #<Queue>)
head+tail: given queue is empty
Queues obtained by applying the technique called Implicit Recursive Slowdown. Provides a amortized running time of O(1) for the operations head , tail and enqueue . Implicit Recursive Slowdown combines laziness and technique called Recursive Slow-Down developed by Kaplan and Tarjan in their paper Persistant Lists with Catenation via Recursive Slow-Down.
syntax
( Queue A)
- : (U (Deep Positive-Byte) (Shallow Positive-Byte))
#<Deep>
In the above example, the queue obtained will have 1 as its head element.
In the above example, enqueue adds the element 10 to of (queue 123456) and returns (queue 12345610).
procedure
( queue->list que)→(Queue A)
- : (Listof Positive-Byte)
'(10 2 34 4 15 6)
- : (Listof Nothing)
'()
- : (Listof Positive-Index)
'(2 3 4 5 6 7)
- : (Listof Positive-Index)
'(1 4 9 16 25 36)
fold currently does not produce correct results when the given function is non-commutative.
- : Integer [more precisely: Nonnegative-Integer]
21
- : Integer [more precisely: Positive-Integer]
518400
- : (Listof Positive-Byte)
'(6)
- : (Listof Positive-Byte)
'(1 2 3 4)
- : (Listof Positive-Byte)
'(1 2 3 4 5)
- : (Listof Positive-Byte)
'(1 2 3 4 5)
- : (Listof Positive-Byte)
'(5 6)
- : (Listof Positive-Byte)
'(6)
- : Boolean
#f
- : Boolean
#f
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
procedure
( build-queue sizefunc)→(Queue A)
size:Naturalfunc:(Natural->A)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(0 1 4 9 16)
Bootstrapped Queue use a structural bootstrapping technique called Structural Decomposition. The data structure gives a worst case running time of O(1) for the operation head and O(log*(n)) for tail and enqueue . Internally uses Physicist’s Queue.
syntax
( Queue A)
- : (U (IntQue Integer) Null)
#<IntQue>
In the above example, the queue obtained will have 1 as its first element.
In the above example, (enqueue 10(queue 123456)) adds the 10 to the queue (queue 123456). 10 as its last element.
In the above example, (tail (queue 123456)), removes the head of the given queue returns (queue 23456).
procedure
( queue->list que)→(Queue A)
- : (Listof Integer)
'(10 2 34 4 15 6)
- : (Listof Nothing)
'()
- : (Listof Integer)
'(2 3 4 5 6 7)
- : (Listof Integer)
'(1 4 9 16 25 36)
fold currently does not produce correct results when the given function is non-commutative.
- : (Listof Integer)
'(6)
- : (Listof Integer)
'(1 2 3 4)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(5 6)
- : (Listof Integer)
'(6)
- : Boolean
#f
- : Boolean
#f
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
procedure
( build-queue sizefunc)→(Queue A)
size:Naturalfunc:(Natural->A)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(0 1 4 9 16)
Real-Time Queues eliminate the amortization by employing laziness and a technique called Scheduling. The data structure gives a worst case running time of O(1) for the operations head , tail and enqueue .
syntax
( Queue A)
- : #(struct:Queue
((Rec
g301744
(U (Boxof (U (-> (Pairof Integer g301744)) (Pairof Integer g301744)))
Null))
(Listof Integer)
(Rec
g301747
(U (Boxof (U (-> (Pairof Integer g301747)) (Pairof Integer g301747)))
Null))))
#<Queue>
In the above example, the queue obtained will have 1 as its first element.
In the above example, (enqueue 10que) adds 10 to the end of (queue 123456) and returns (queue 12345610).
- : #(struct:Queue
((Rec
g301840
(U (Boxof (U (-> (Pairof Integer g301840)) (Pairof Integer g301840)))
Null))
(Listof Integer)
(Rec
g301843
(U (Boxof (U (-> (Pairof Integer g301843)) (Pairof Integer g301843)))
Null))))
#<Queue>
tail: given queue is empty
In the above example, (tail (queue 123456)), returns (queue 23456).
procedure
( queue->list que)→(Queue A)
- : (Listof Integer)
'(10 2 34 4 15 6)
- : (Listof Integer)
'(2 3 4 5 6 7)
- : (Listof Integer)
'(1 4 9 16 25 36)
fold currently does not produce correct results when the given function is non-commutative.
- : (Listof Integer)
'(6)
- : (Listof Integer)
'(1 2 3 4)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(5 6)
- : (Listof Integer)
'(6)
- : Boolean
#f
- : Boolean
#f
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
procedure
( build-queue sizefunc)→(Queue A)
size:Naturalfunc:(Natural->A)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(0 1 4 9 16)
- : (Pairof
Integer
#(struct:Queue
((Rec
g302223
(U (Boxof (U (-> (Pairof Integer g302223)) (Pairof Integer g302223)))
Null))
(Listof Integer)
(Rec
g302226
(U (Boxof (U (-> (Pairof Integer g302226)) (Pairof Integer g302226)))
Null)))))
'(1 . #<Queue>)
- : (Pairof
Integer
#(struct:Queue
((Rec
g302242
(U (Boxof (U (-> (Pairof Integer g302242)) (Pairof Integer g302242)))
Null))
(Listof Integer)
(Rec
g302245
(U (Boxof (U (-> (Pairof Integer g302245)) (Pairof Integer g302245)))
Null)))))
'(0 . #<Queue>)
head+tail: given queue is empty
Similar to real-time queues in many ways. But the implementation is much more complicated than Real-Time Queue. Uses a technique called Global Rebuilding. The data structure gives a worst case running time of O(1) for the operations head , tail and enqueue .
syntax
( Queue A)
- : #(struct:Queue
(Integer
(Listof Positive-Byte)
(U (Appending Positive-Byte)
(Done Positive-Byte)
(Reversing Positive-Byte)
Null)
Integer
(Listof Positive-Byte)))
#<Queue>
In the above example, the queue obtained will have 1 as its head element.
In the above example, enqueue adds the element 10 to (queue 123456) and returns (queue 12345610).
In the above example, (tail (queue 123456)), returns (queue 23456).
procedure
( queue->list que)→(Queue A)
- : (Listof Positive-Byte)
'(10 2 34 4 15 6)
- : (Listof Nothing)
'()
- : (Listof Positive-Index)
'(2 3 4 5 6 7)
- : (Listof Positive-Index)
'(1 4 9 16 25 36)
fold currently does not produce correct results when the given function is non-commutative.
- : Integer [more precisely: Nonnegative-Integer]
21
- : Integer [more precisely: Positive-Integer]
518400
- : (Listof Positive-Byte)
'(6)
- : (Listof Positive-Byte)
'(1 2 3 4)
- : (Listof Positive-Byte)
'(1 2 3 4 5)
- : (Listof Positive-Byte)
'(1 2 3 4 5)
- : (Listof Positive-Byte)
'(5 6)
- : (Listof Positive-Byte)
'(6)
- : Boolean
#f
- : Boolean
#f
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
- : Boolean
#t
procedure
( build-queue sizefunc)→(Queue A)
size:Naturalfunc:(Natural->A)
- : (Listof Integer)
'(1 2 3 4 5)
- : (Listof Integer)
'(0 1 4 9 16)
- : (Pairof
Positive-Byte
#(struct:Queue
(Integer
(Listof Positive-Byte)
(U (Appending Positive-Byte)
(Done Positive-Byte)
(Reversing Positive-Byte)
Null)
Integer
(Listof Positive-Byte))))
'(1 . #<Queue>)
- : (Pairof
Integer
#(struct:Queue
(Integer
(Listof Integer)
(U (Appending Integer) (Done Integer) (Reversing Integer) Null)
Integer
(Listof Integer))))
'(0 . #<Queue>)
head+tail: given queue is empty