diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-04-05 15:10:29 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-15 23:01:26 -0400 |
commit | 34ffd36a0c43bab1e8ee675e1d9cd31133c5d116 (patch) | |
tree | 85a7b01ca6f841450fe82b3da6de96888c0b7ae7 /heap.ml | |
parent | d1cb824564ecb06b99c6c2e4fc073f8ca4bcfd9a (diff) | |
download | roux-34ffd36a0c43bab1e8ee675e1d9cd31133c5d116.tar.gz |
add popd in the Heap module
Diffstat (limited to 'heap.ml')
-rw-r--r-- | heap.ml | 12 |
1 files changed, 7 insertions, 5 deletions
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 |