From 34ffd36a0c43bab1e8ee675e1d9cd31133c5d116 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Sun, 5 Apr 2015 15:10:29 -0400 Subject: add popd in the Heap module --- heap.ml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'heap.ml') diff --git a/heap.ml b/heap.ml index 502fd57..79081b9 100644 --- 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 -- cgit 1.4.1