conduit-algorithms 0.0.5.0 → 0.0.6.0
raw patch · 3 files changed
+21/−19 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog +3/−0
- Data/Conduit/Algorithms.hs +17/−18
- conduit-algorithms.cabal +1/−1
ChangeLog view
@@ -1,3 +1,6 @@+Version 0.0.6.0 2017-10-09 by luispedro+ * More efficient mergeC conduit+ Version 0.0.5.0 2017-10-03 by luispedro * Add enumerateC conduit * Better mergeC conduit (list case)
Data/Conduit/Algorithms.hs view
@@ -20,7 +20,7 @@ import qualified Data.Conduit as C import qualified Data.Conduit.Internal as CI import qualified Data.Set as S-import Data.List (foldl')+import Data.List (sortBy, insertBy) import Control.Monad.Trans.Class (lift) import Data.Conduit.Algorithms.Utils (awaitJust)@@ -81,30 +81,29 @@ mergeC [a] = a mergeC [a,b] = mergeC2 a b mergeC cs = CI.ConduitM $ \rest -> let- --go :: [CI.Pipe () i o () m ()] -> CI.Pipe () i o () m () go [] = rest ()- go st = do- st' <- mapM norm1 st- case gettop st' of- Nothing -> rest ()- Just (CI.HaveOutput c_next _ v, fs, next) ->- CI.HaveOutput (go (c_next:next)) (sequence_ fs) v- _ -> error "This should be impossible (mergeC/go/case-gettop)"+ go allc@(CI.HaveOutput c_next _ v:larger) =+ CI.HaveOutput (norm1 c_next >>= go . insert1 larger) (finalizeAll allc) v+ go _ = error "This situation should have been impossible (mergeC/compareHO)"+ insert1 larger CI.Done{} = larger+ insert1 larger c = insertBy compareHO c larger norm1 :: Monad m => CI.Pipe () i o () m () -> CI.Pipe () i o () m (CI.Pipe () i o () m ()) norm1 c@CI.HaveOutput{} = return c norm1 c@CI.Done{} = return c norm1 (CI.PipeM p) = lift p >>= norm1 norm1 (CI.NeedInput _ next) = norm1 (next ()) norm1 (CI.Leftover next ()) = norm1 next- gettop = foldl' collect Nothing- collect cur CI.Done{} = cur- collect Nothing c@(CI.HaveOutput _ f _) = Just (c, [f], [])- collect (Just (best_c@(CI.HaveOutput _ _ best_v), fs, next)) c@(CI.HaveOutput _ f v)- | v >= best_v = Just (best_c, f:fs, c:next)- | otherwise = Just (c, f:fs, best_c:next)- collect _ _ = error "This situation should be impossible (mergeC/collect)"-- in go (map (($ CI.Done) . CI.unConduitM) cs)+ isHO CI.HaveOutput{} = True+ isHO _ = False+ compareHO (CI.HaveOutput _ _ a) (CI.HaveOutput _ _ b) = compare a b+ compareHO _ _ = error "This situation should have been impossible (mergeC/compareHO)"+ finalizeAll [] = return ()+ finalizeAll (CI.HaveOutput _ f _ : larger) = f >> finalizeAll larger+ finalizeAll (_ :larger) = finalizeAll larger+ in do+ let st = map (($ CI.Done) . CI.unConduitM) cs+ st' <- mapM norm1 st+ go . sortBy compareHO . filter isHO $ st' -- | Take two sorted sources and merge them.
conduit-algorithms.cabal view
@@ -1,5 +1,5 @@ name: conduit-algorithms-version: 0.0.5.0+version: 0.0.6.0 synopsis: Conduit-based algorithms description: Algorithms on Conduits, including higher level asynchronous processing and some other utilities.