priority-queue 0.2.1 → 0.2.2
raw patch · 2 files changed
+28/−4 lines, 2 filesdep ~containers
Dependency ranges changed: containers
Files
- priority-queue.cabal +12/−2
- src/Data/PriorityQueue.hs +16/−2
priority-queue.cabal view
@@ -1,5 +1,5 @@ name: priority-queue-version: 0.2.1+version: 0.2.2 stability: provisional license: BSD3 license-file: LICENSE@@ -24,10 +24,20 @@ extensions: CPP if flag(splitBase)- build-depends: base >= 3 && <5, containers+ build-depends: base >= 3 && <5, containers <0.4 else build-depends: base < 3 cpp-options: -DNoMinViewWithKey+ + if !impl(ghc >= 6.12)+ -- There are probably other tests that would tell us we have breakl+ -- (eg perhaps impl(otherhc >= x.y)), but I don't know what they are.+ -- it should be safe to assume it's not there, so this condition is + -- intentionally conservative.+ -- I tried just using another flag to discriminate on the version + -- of 'containers', but then cabal wants to install whatever version + -- it decides it likes best, which is a very bad thing to do.+ cpp-options: -DNoBreakL build-depends: reord >= 0.0.0.2, stateref >= 0.3 && < 0.4, queue >= 0.1.2 && < 0.2
src/Data/PriorityQueue.hs view
@@ -51,7 +51,8 @@ import Data.StateRef import Data.Ord.ReOrd import qualified Data.Map as M-import Data.Sequence as Seq+import qualified Data.Sequence as Seq+import Data.Sequence (Seq, viewl, ViewL(..), (><), (<|), singleton, fromList) import Data.List as List import Data.Foldable as Foldable @@ -172,6 +173,19 @@ minViewWithKey = M.minViewWithKey #endif +breakl :: (a -> Bool) -> Seq a -> (Seq a, Seq a)+#ifdef NoBreakL+-- breakl p xs = (fromList ys, fromList zs)+-- where (ys, zs) = break p (toList xs)+breakl p xs = case viewl xs of+ EmptyL -> (xs, xs)+ x :< xs' + | p x -> (Seq.empty, xs)+ | otherwise -> let (ys, zs) = breakl p xs' in (x <| ys, zs)+#else+breakl = Seq.breakl+#endif+ -- |'on' combinator (Data.Function doesn't always have it) on :: (b -> b -> c) -> (a -> b) -> (a -> a -> c) op `on` f = \x y -> f x `op` f y@@ -179,6 +193,6 @@ -- |given a Seq known to contain at least one item matching the predicate, -- return the (first) matching item and the seq sans that element extractFirstWhere :: (a -> Bool) -> Seq a -> (a, Seq a)-extractFirstWhere p xs = case Seq.breakl p xs of+extractFirstWhere p xs = case breakl p xs of (noMatch, rest) -> case viewl rest of x :< rest -> (x, noMatch >< rest)