hw-fingertree-strict 0.1.0.3 → 0.1.1.0
raw patch · 3 files changed
+35/−15 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ HaskellWorks.Data.PriorityQueue.Strict: take :: Ord k => Int -> PQueue k v -> ([v], PQueue k v)
+ HaskellWorks.Data.PriorityQueue.Strict: takeWithKeys :: Ord k => Int -> PQueue k v -> ([(k, v)], PQueue k v)
Files
- README.md +1/−0
- hw-fingertree-strict.cabal +2/−2
- src/HaskellWorks/Data/PriorityQueue/Strict.hs +32/−13
README.md view
@@ -1,1 +1,2 @@ # hw-fingertree-strict+[](https://circleci.com/gh/haskell-works/hw-fingertree-strict)
hw-fingertree-strict.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: f1b862b22d5d83cf314a1c9f6c15e9533377a9225218e6b3bd7693aa5a50f50b+-- hash: 5c497b01164dee762c3873fb69ffef4ce5f924eaed8074380983ce4362edd761 name: hw-fingertree-strict-version: 0.1.0.3+version: 0.1.1.0 synopsis: Generic strict finger-tree structure description: A general sequence representation with arbitrary annotations, for use as a base for implementations of
src/HaskellWorks/Data/PriorityQueue/Strict.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE MultiParamTypeClasses #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Safe #-}@@ -40,19 +39,21 @@ -- ----------------------------------------------------------------------------- -module HaskellWorks.Data.PriorityQueue.Strict (- PQueue,+module HaskellWorks.Data.PriorityQueue.Strict+ ( PQueue -- * Construction- empty,- singleton,- union,- insert,- add,- fromList,+ , empty+ , singleton+ , union+ , insert+ , add+ , fromList -- * Deconstruction- null,- minView,- minViewWithKey+ , null+ , minView+ , minViewWithKey+ , takeWithKeys+ , take ) where import Control.Arrow ((***))@@ -61,7 +62,7 @@ import Data.Monoid import GHC.Generics (Generic) import HaskellWorks.Data.FingerTree.Strict (FingerTree, Measured (..), ViewL (..), (<|), (><), (|>))-import Prelude hiding (null)+import Prelude hiding (null, take) import qualified Data.Semigroup as S import qualified HaskellWorks.Data.FingerTree.Strict as FT@@ -169,6 +170,24 @@ -- minView :: Ord k => PQueue k v -> Maybe (v, PQueue k v) minView q = fmap (snd *** id) (minViewWithKey q)++-- | /O(n)/ for number of elements taken.+takeWithKeys :: Ord k => Int -> PQueue k v -> ([(k, v)], PQueue k v)+takeWithKeys = go []+ where go :: Ord k => [(k, v)] -> Int -> PQueue k v -> ([(k, v)], PQueue k v)+ go as n q | n > 0 = case minViewWithKey q of+ Just (a, r) -> go (a:as) (n - 1) r+ _ -> (reverse as, q)+ go as _ q = (reverse as, q)++-- | /O(n)/ for number of elements taken.+take :: Ord k => Int -> PQueue k v -> ([v], PQueue k v)+take = go []+ where go :: Ord k => [v] -> Int -> PQueue k v -> ([v], PQueue k v)+ go as n q | n > 0 = case minView q of+ Just (a, r) -> go (a:as) (n - 1) r+ _ -> (reverse as, q)+ go as _ q = (reverse as, q) -- | /O(1)/ for the element, /O(log(n))/ for the reduced queue. -- Returns 'Nothing' for an empty map, or the minimal (priority, value)