-- | Validity testingmodule Validity.BinomialQueue ( validShape , precedesProperly ) whereimport BinomialQueue.Internals-- | Does the heap have a valid shape?validShape :: MinQueue a -> BoolvalidShape (MinQueue f) = validShapeF f validShapeF :: BinomForest rk a -> BoolvalidShapeF (Cons _ f) = validShapeF fvalidShapeF (Skip Nil) = FalsevalidShapeF (Skip _f) = TruevalidShapeF Nil = True -- | Takes an element and a priority queue. Checks that the queue is in heap-- order and that the element is less than or equal to all elements of the-- queue.precedesProperly :: Ord a => a -> MinQueue a -> BoolprecedesProperly a (MinQueue q) = precedesProperlyF a q -- | Takes an element and a forest. Checks that the forest is in heap order-- and that the element is less than or equal to all elements of the forest.precedesProperlyF :: (Ord a, TreeValidity rk) => a -> BinomForest rk a -> BoolprecedesProperlyF _ Nil = TrueprecedesProperlyF the_min (Skip f) = precedesProperlyF the_min fprecedesProperlyF the_min (Cons t ts) = precedesProperlyTree the_min t && precedesProperlyF the_min ts -- | Takes an element and a tree. Checks that the tree is in heap order-- and that the element is less than or equal to all elements of the tree.precedesProperlyTree :: (Ord a, TreeValidity rk) => a -> BinomTree rk a -> BoolprecedesProperlyTree the_min (BinomTree a ts) = the_min <= a && precedesProperlyRk a ts -- | A helper class for order validity checkingclass TreeValidity rk where -- | Takes an element and a collection of trees. Checks that the collection -- is in heap order and that the element is less than or equal to all -- elements of the collection. precedesProperlyRk :: Ord a => a -> rk a -> Boolinstance TreeValidity Zero where precedesProperlyRk _ ~Zero = Trueinstance TreeValidity rk => TreeValidity (Succ rk) where precedesProperlyRk the_min (Succ t q) = precedesProperlyTree the_min t && precedesProperlyRk the_min q