
module AbstractHeap

(**** logic declarations *****)

use int.Int
use bag.Bag
use bag_of_integers.Bag_integers

(* abstract interface for heaps *)

type logic_heap
function model (h:logic_heap): (bag int)

use ref.Ref

val create (sz:int) : ref logic_heap
  requires { 0 <= sz }
  ensures  { model !result = empty_bag }

val insert (this:ref logic_heap) (e:int) : unit writes {this}
  ensures  { model !this = add e (model (old !this)) }

val extractMin (this:ref logic_heap) : int writes {this}
  requires { model !this <> empty_bag }
  ensures  { result = min_bag (model (old !this)) /\
    model (old !this) = add result (model !this) /\
    card (model (old !this)) = (card (model !this)) + 1
  }

end
