{-# LANGUAGE TypeSynonymInstances #-}{-|
A heap is a container supporting the insertion of elements and the extraction of the minimum element.
This library models the implementation of asymptotically optimal purely functional heaps given by Brodal and Okasaki in their paper \"Optimal Purely Functional Priority Queues\".
The Coq proof assistant has been used to prove this implementation correct.
The proofs are available in the Cabal package or at <http://code.google.com/p/priority-queues/>.
The default implementation is lazy.
A strict implementation is available in this package as "Data.MeldableHeap.Strict".
The lazy implementation is available in this module ("Data.MeldableHeap") or in "Data.MeldableHeap.Lazy".
-}moduleData.MeldableHeap(PQ(),empty,toList,insert,findMin,extractMin,meld)whereimportqualifiedData.MeldableHeap.LazyasLtypePQ=L.PQ-- |'empty' is the heap with no elementsempty::Orda=>PQaempty=L.empty{- |
'toList' (O(n)) returns a list of the elements in the heap in some arbitrary order.
> [] == toList empty
-}toList::Orda=>PQa->[a]toList=L.toList{- |
'insert' (O(1)) adds an element to a heap.
> [1,2,1,0] == toList $ insert 1 $ insert 0 $ insert 2 $ insert 1 $ empty
-}insert::Orda=>a->PQa->PQainsert=L.insert{- |
'findMin' (O(1)) returns the minimum element of a nonempty heap.
> Just 0 == findMin $ insert 0 $ insert 2 $ insert 1 $ empty
-}findMin::Orda=>PQa->MaybeafindMin=L.findMin{- |
'extractMin' (O(lg n)) returns (if the heap is nonempty) a pair containing the minimum element and a heap that contains all of the other elements.
It does not remove copies of the minimum element if some exist in the heap.
> (0,[2,1]) == let x = insert 0 $ insert 2 $ insert 1 $ empty in let Just (p,q) = extractMin x in (p,toList q)
-}extractMin::Orda=>PQa->Maybe(a,PQa)extractMin=L.extractMin{- |
'meld' (O(1)) joins two heaps P and Q into a heap containing exactly the elements in P and Q. It does not remove duplicates.
> [2,1,0,2,1,0] == let x = insert 0 $ insert 2 $ insert 1 $ empty in toList (meld x x)
-}meld::Orda=>PQa->PQa->PQameld=L.meld