packages feed

pqueue-1.6.0.0 / tests / Validity / PQueue / Prio / BinomialQueue.hs

-- | Validity testingmodule Validity.PQueue.Prio.BinomialQueue  ( validShapeF  , precedesProperlyF  ) whereimport Data.PQueue.Prio.Internals-- | Does the heap have a valid shape?validShapeF :: BinomForest rk k a -> BoolvalidShapeF (Cons _ f) = validShapeF fvalidShapeF (Skip Nil) = FalsevalidShapeF (Skip _f) = TruevalidShapeF Nil = True  -- | 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 k, TreeValidity rk) => k -> BinomForest rk k 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 k, TreeValidity rk) => k -> BinomTree rk k a -> BoolprecedesProperlyTree the_min (BinomTree k ts) = the_min <= k && precedesProperlyRk k 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 k => k -> rk k 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