packages feed

mmsyn2 0.1.8.0 → 0.2.0.0

raw patch · 5 files changed

+97/−4 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ CaseBi.Unboxed: filterP :: (Ord a, Unbox a, Unbox b) => ((a, b) -> Bool) -> [(a, b)] -> Vector (a, b)
+ CaseBi.Unboxed: getBFst :: (Ord a, Unbox a, Unbox b) => Vector (a, b) -> b -> [a] -> [b]
+ CaseBi.Unboxed: getBFst' :: (Ord a, Unbox a, Unbox b) => (b, Vector (a, b)) -> a -> b
+ CaseBi.Unboxed: getBFstV :: (Ord a, Unbox a, Unbox b) => Vector (a, b) -> b -> Vector a -> Vector b
+ CaseBi.Unboxed: sortFst :: (Ord a, Unbox a, Unbox b) => [(a, b)] -> [(a, b)]
+ CaseBi.Unboxed: sortFstV :: (Ord a, Unbox a, Unbox b) => [(a, b)] -> Vector (a, b)

Files

CaseBi.hs view
@@ -2,6 +2,7 @@ -- Module      :  CaseBi -- Copyright   :  (c) OleksandrZhabenko 2019 -- License     :  MIT+-- Stability   :  Experimental -- Maintainer  :  olexandr543@yahoo.com -- -- A library that can be used as a @case ... of@ constuction analogue for the multiple @Ord a => a -> b@ transformations and data representation.
+ CaseBi/Unboxed.hs view
@@ -0,0 +1,87 @@+-- |+-- Module      :  CaseBi.Unboxed+-- Copyright   :  (c) OleksandrZhabenko 2019-2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--++module CaseBi.Unboxed (+-- * Function that can be used instead of @case ... of@ construction+--+-- > case var of +-- >   a1 -> b1+-- >   a2 -> b2+-- >   a3 -> b3+-- >   ...+-- >   an -> bn+-- >   _  -> def+-- +-- for efficiency or other data representation+  getBFst', getBFst, getBFstV, +-- * Additional functions that are used to sort a list of pairs (which can be obtained e. g. by 'Prelude.zip')+  sortFst, sortFstV,+-- ** Function that can be used for changing the @Vector (a, b)@ during its creation +  filterP+) where++import qualified Data.Vector.Unboxed as V (Vector,unsafeIndex,unsafeSlice,length,fromList,map)+import qualified Data.List as L (groupBy,nubBy)+import Data.Vector.Unboxed.Base++-- | A variant of the 'CaseBi.getBFst'' function that operates on the unboxed 'V.Vector'.+-- +getBFst' +  :: (Ord a, Unbox a, Unbox b) +  => (b, V.Vector (a, b)) -- ^ @b@ is a default value that can be substituted if there is no correspendence in the set of @(a, b)@ tuples (the 'otherwise' or irrefutable pattern analogue). Vector of the @(a, b)@ tuples that must be sorted in ascending order for the first argument. If there are several pairs @(a, b)@ with the same @a@, the function gives a resulting @b@ as if there is only the first one+  -> a -- ^ an element for which the corresponding resulting b must be found+  -> b -- ^ the result+getBFst' (def, vec) l | if compare l (fst (V.unsafeIndex vec 0)) == LT then True else compare l (fst (V.unsafeIndex vec (V.length vec - 1))) == GT = def+                      | compare (V.length vec) 2 /= LT = if compare l (fst (V.unsafeIndex vec ((V.length vec `quot` 2) - 1))) /= GT+  then getBFst' (def, (V.unsafeSlice 0 (V.length vec `quot` 2) vec)) l +  else getBFst' (def, (V.unsafeSlice (V.length vec `quot` 2) (V.length vec - (V.length vec `quot` 2)) vec)) l +                      | otherwise = snd (V.unsafeIndex vec 0)+{-# INLINE getBFst' #-}+                   +-- | A variant of the 'CaseBi.getBFstV' that operates on the unboxed 'V.Vector'.+-- +getBFstV :: (Ord a, Unbox a, Unbox b) => V.Vector (a, b) -- ^ Vector of the @(a, b)@ tuples that are sorted in ascending order for the first argument+  -> b -- ^ a default value that can be substituted if there is no correspendence in the set of @(a, b)@ tuples (the 'otherwise' or irrefutable pattern analogue)+  -> V.Vector a -- ^ a Vector needed to be transformed accordingly to the correct @(a, b)@ tuple pairs+  -> V.Vector b -- ^ the resulting Vector+getBFstV c y = V.map (getBFst' (y, c))+{-# INLINE getBFstV #-}++-- | A variant of the 'CaseBi.getBFst' that operates on the unboxed 'V.Vector'.+-- +getBFst :: (Ord a, Unbox a, Unbox b) => V.Vector (a, b) -- ^ Vector of the @(a, b)@ tuples that must be sorted in ascending order for the first argument+  -> b -- ^ a default value that can be substituted if there is no correspendence in the set of @(a, b)@ tuples (the 'otherwise' or irrefutable pattern analogue)+  -> [a] -- ^ a list of values needed to be transformed accordingly to the correct @(a, b)@ tuple pairs+  -> [b] -- ^ the resulting list+getBFst c y = map (getBFst' (y, c))+{-# INLINE getBFst #-}++-- | A variant of the 'CaseBi.sortFst' that operates on the unboxed 'V.Vector'. It is inspired by the work: https://wiki.haskell.org/Introduction+sortFst :: (Ord a, Unbox a, Unbox b) => [(a, b)] -> [(a, b)]+sortFst xs = if null xs then [] else sortFst (filter (\(x, _) -> compare x (fst (head xs)) == LT) xs) ++ filter (\(x, _) -> x == (fst (head xs))) xs ++ +  sortFst (filter (\(x, _) -> compare x (fst (head xs)) == GT) xs)+{-# INLINE sortFst #-}           ++-- | A variant of the 'CaseBi.sortFstV' that operates on the unboxed 'V.Vector'.+--+sortFstV +  :: (Ord a, Unbox a, Unbox b) => [(a, b)] -- ^ The list of conditions that is then converted to the corresponding Vector+   -> V.Vector (a, b) -- ^ the resulting sorted Vector that can be used further in getBFst' and its successors.+sortFstV = V.fromList . L.nubBy (\(x, _) (y, _) -> x == y) . sortFst+{-# INLINE sortFstV #-}++-- | A variant of the 'CaseBi.filterP' that operates on the unboxed 'V.Vector'.+filterP +  :: (Ord a, Unbox a, Unbox b) => ((a, b) -> Bool) -- ^ The predicate @p@ used to select the only one value of @b@ in the pairs @(a, b)@ with the same @a@. +  -- ^ If there are several pairs @(a, b)@ for the same @a@ that satisfies a predicate then the first one is used. For large @[(a, b)]@ +  -- ^ it can be rather complex.+  -> [(a, b)] -- ^ The list of @(a, b)@ sorted in the ascending order by the first element a (e. g. by the 'sortFst' function)+  -> V.Vector (a, b) -- ^ The resulting filtered @Vector (a, b)@ that can be used for getFstB' and its successor functions.+--+filterP p xs = V.fromList . concatMap (\x -> take 1 . dropWhile (not . p) $ x) . L.groupBy (\(x1,_) (x2,_) -> x1 == x2) $ xs+{-# INLINE filterP #-}
ChangeLog.md view
@@ -6,7 +6,7 @@  ## 0.1.3.0 -- 2019-09-27 -* First release revised B. Some performance changes and changing the imported functions. +* First release revised B. Some performance changes and changing the imported functions. Moreover, fixed constraints in cabal file. Make more exact the vector usage.  ## 0.1.4.0 -- 2019-09-28@@ -35,4 +35,8 @@ ## 0.1.8.0 -- 2020-05-14  * First version revised H. Changed the dependency bounds so that it now can be compiled with GHC 8.10* series. Some documentation improvements.++## 0.2.0.0 -- 2020-10-15++* Second version. Added a new module CaseBi.Unboxed with functions that operate on the unboxed vectors. 
README.md view
@@ -2,3 +2,4 @@  mmsyn2 is the library that can be used for multiple (Ord a) => a -> b transformations. +Since the 0.2.0.0 version there are two modules with the similar functionality: for boxed and unboxed vectors. The last one is probably more efficient in some cases.
mmsyn2.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/  name:                mmsyn2-version:             0.1.8.0+version:             0.2.0.0 synopsis:            The library that can be used for multiple (Ord a) => a -> b transformations description:         The library that can be used for optimization or another representation of multiple (Ord a) => a -> b transformations homepage:            https://oleksandrzhabenko.github.io/mmsyn2@@ -10,14 +10,14 @@ license-file:        LICENSE author:              OleksandrZhabenko maintainer:          olexandr543@yahoo.com--- copyright:+copyright:           Oleksandr Zhabenko category:            Development build-type:          Simple extra-source-files:  ChangeLog.md README.md cabal-version:       >=1.10  library-  exposed-modules:     CaseBi+  exposed-modules:     CaseBi, CaseBi.Unboxed   -- other-modules:   -- other-extensions:   build-depends:       base >=4.3 && <4.15, vector >=0.11 && <0.14