[m-rev.] for review 2/2: Refine Micheal's pqueue changes

Paul Bone paul at bone.id.au
Sun Nov 24 15:42:15 AEDT 2013


For review by anyone.

Branches: master

---

Refine Micheal's pqueue changes

library/pqueue.m:
    Refine Micheal's changes where necessary to conform to our style.

NEWS:
    Updated news file.
---
 NEWS             |  6 ++++++
 library/pqueue.m | 23 ++++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index 4abef36..ef60322 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,12 @@ Changes to the Mercury standard library:
 * We have added the following predicates to the list module: foldr2/6 and
   foldr3/8.
 
+* We have added the following predicates to the pqueue module:
+  is_empty/1, peek/3, peek_key/2, peek_value/2, det_peek/3 and merge/3.
+  We have also added the following fuctions to the pqueue module:
+  det_peek_key/1 and det_peek_value/1.
+
+
 NEWS for Mercury 13.05.2
 ------------------------
 
diff --git a/library/pqueue.m b/library/pqueue.m
index 48e2d11..8574ad8 100644
--- a/library/pqueue.m
+++ b/library/pqueue.m
@@ -85,6 +85,7 @@
 
     % Merges all the entries of one priority queue with another, returning
     % the merged list.
+    %
 :- func pqueue.merge(pqueue(K, V), pqueue(K, V)) = pqueue(K, V).
 :- pred pqueue.merge(pqueue(K, V)::in, pqueue(K, V)::in, pqueue(K, V)::out)
     is det.
@@ -149,14 +150,17 @@ pqueue.peek_value(pqueue(_, _, V, _, _), V).
 %---------------------------------------------------------------------------%
 
 pqueue.det_peek(PQ, K, V) :-
-    ( pqueue.peek(PQ, J, T) ->
-        K = J, V = T
+    ( pqueue.peek(PQ, KPrime, VPrime) ->
+        K = KPrime,
+        V = VPrime
     ;
         unexpected($file, $pred, "empty priority queue")
     ).
 
-pqueue.det_peek_key(PQ) = K :- pqueue.det_peek(PQ, K, _).
-pqueue.det_peek_value(PQ) = V :- pqueue.det_peek(PQ, _, V).
+pqueue.det_peek_key(PQ) = K :-
+    pqueue.det_peek(PQ, K, _).
+pqueue.det_peek_value(PQ) = V :-
+    pqueue.det_peek(PQ, _, V).
 
 %---------------------------------------------------------------------------%
 
@@ -187,7 +191,7 @@ pqueue.insert_2(K, V, pqueue(D0, K0, V0, L0, R0), empty,
 pqueue.insert_2(K, V, empty, pqueue(D0, K0, V0, L0, R0),
         pqueue(0, K, V, empty, empty), pqueue(D0, K0, V0, L0, R0)).
 pqueue.insert_2(K, V, pqueue(D0, K0, V0, L0, R0),
-                pqueue(D1, K1, V1, L1, R1), PQ1, PQ2) :-
+        pqueue(D1, K1, V1, L1, R1), PQ1, PQ2) :-
     ( D0 > D1 ->
         pqueue.insert(K, V, pqueue(D1, K1, V1, L1, R1), PQ2),
         PQ1 = pqueue(D0, K0, V0, L0, R0)
@@ -235,10 +239,11 @@ pqueue.merge(A, B) = C :-
     pqueue.merge(A, B, C).
 
 pqueue.merge(A, B, C) :-
-  ( pqueue.length(A) =< pqueue.length(B) ->
-      pqueue.merge2(A, B, C)
-  ;
-      pqueue.merge2(B, A, C) ).
+    ( pqueue.length(A) =< pqueue.length(B) ->
+        pqueue.merge2(A, B, C)
+    ;
+        pqueue.merge2(B, A, C)
+    ).
 
 :- pred pqueue.merge2(pqueue(K, V)::in, pqueue(K, V)::in, pqueue(K, V)::out)
     is det.
-- 
1.8.4.rc3




More information about the reviews mailing list