commit 34ffd36a0c43bab1e8ee675e1d9cd31133c5d116
parent d1cb824564ecb06b99c6c2e4fc073f8ca4bcfd9a
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Sun, 5 Apr 2015 15:10:29 -0400
add popd in the Heap module
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/heap.ml b/heap.ml
@@ -3,6 +3,7 @@ module Heap: sig
type 'a t
val create: ('a -> 'a -> int) -> 'a t
val add: 'a t -> 'a -> unit
+ val popd: 'a t -> unit
val pop: 'a t -> 'a option
val top: 'a t -> 'a option
end = struct
@@ -48,11 +49,12 @@ end = struct
then ch0 else ch1 in
if cmp arr.(i) arr.(mn) <= 0 then () else
(swap arr i mn; bbldn cmp arr mn len)
- let pop ({arr; len; cmp} as hp) =
- if len = 0 then None else
- let t = top hp in
+ let popd ({arr; len; cmp} as hp) =
+ if len = 0 then () else
arr.(1) <- arr.(len);
hp.len <- len - 1;
- bbldn cmp arr 1 len;
- t
+ bbldn cmp arr 1 len
+ let pop hp =
+ let r = top hp in
+ popd hp; r
end