compressed 3.10 → 3.11
raw patch · 5 files changed
+41/−9 lines, 5 filesdep ~basedep ~comonaddep ~pointed
Dependency ranges changed: base, comonad, pointed
Files
- CHANGELOG.markdown +10/−0
- README.markdown +1/−1
- compressed.cabal +5/−5
- src/Data/Compressed/Internal/LZ78.hs +8/−1
- src/Data/Compressed/RunLengthEncoding.hs +17/−2
CHANGELOG.markdown view
@@ -1,3 +1,13 @@+3.11+----+* Cleaned up warnings on modern GHC versions+* Disabled some rules that weren't firing++3.10.1+------+* `instance MonadZip LZ78`+* `instance MonadZip RLE`+ 3.10 ---- * Updated dependencies
README.markdown view
@@ -1,7 +1,7 @@ compressed ========== -[](http://travis-ci.org/ekmett/compressed)+[](https://hackage.haskell.org/package/compressed) [](http://travis-ci.org/ekmett/compressed) This package provides compressed data structures for LZ78 and run length encoding. Their primary benefit is that if you go to decompress them you can decompress them in an arbitrary `Monoid`.
compressed.cabal view
@@ -1,6 +1,6 @@ name: compressed category: Data, Compression, MapReduce-version: 3.10+version: 3.11 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -11,7 +11,7 @@ bug-reports: http://github.com/ekmett/compressed/issues copyright: Copyright (C) 2011 Edward A. Kmett synopsis: Compressed containers and reducers-description: Compressed containers and reducers+description: Compressed containers and reducers. build-type: Simple extra-source-files: .ghci@@ -34,9 +34,9 @@ hashable >= 1.1.2.1 && < 1.3, unordered-containers >= 0.2.1 && < 0.3, semigroups >= 0.8.3.1 && < 1,- semigroupoids >= 4 && < 5,- comonad >= 4 && < 5,- pointed >= 4 && < 5,+ semigroupoids >= 4 && < 6,+ comonad >= 4 && < 6,+ pointed >= 4 && < 6, keys >= 3.10 && < 4, reducers >= 3.10 && < 4
src/Data/Compressed/Internal/LZ78.hs view
@@ -43,7 +43,11 @@ , entries ) where +#if __GLASGOW_HASKELL__ < 710 import Control.Applicative+import Data.Traversable+#endif+import Control.Monad.Zip import qualified Data.Sequence as Seq import Data.Sequence ((|>)) import qualified Data.Map as Map@@ -54,7 +58,6 @@ import Data.Function (on) import Data.Key as Key import Data.Foldable-import Data.Traversable import Data.Semigroup import Data.Pointed import Text.Read@@ -214,6 +217,10 @@ Entry i a <- decode (entries as) Entry j b <- decode (entries (k a)) return $ Entry (i,j) b++instance MonadZip LZ78 where+ mzipWith = Key.zipWith+ munzip as = (fmap fst as, fmap snd as) instance Adjustable LZ78 where adjust f i = fmap extract . encode . adjust (Entry (-1) . f . extract) i . decode . entries
src/Data/Compressed/RunLengthEncoding.hs view
@@ -28,6 +28,7 @@ , runLength , decode , encode+ , encodeList , recode , toRuns , fromRuns@@ -47,7 +48,10 @@ import Data.Generator import Data.Pointed import Data.Key+#if __GLASGOW_HASKELL__ < 710 import Control.Applicative+#endif+import Control.Monad.Zip -- | A single run with a strict length data Run a = Run {-# UNPACK #-} !Int a deriving (Eq,Show)@@ -176,6 +180,16 @@ (>>) = (*>) RLE xs >>= f = RLE $ mconcat [ mconcat $ replicate n (getRLE (f a)) | Run n a <- toList xs ] +instance MonadZip RLE where+ munzip as = (fmap fst as, fmap snd as)+ mzipWith f (RLE as0) (RLE bs0) = RLE $ F.fromList $ go (toList as0) (toList bs0) where+ go [] _ = []+ go _ [] = []+ go (Run n a : as) (Run m b : bs) = case compare n m of+ LT -> Run n (f a b) : go as (Run (m-n) b:bs)+ EQ -> Run n (f a b) : go as bs+ GT -> Run m (f a b) : go (Run (n-m) a:as) bs+ instance Eq a => Reducer a (RLE a) where unit = pure cons a (RLE r) = case viewl r of@@ -251,8 +265,9 @@ encode :: (Generator c, Eq (Elem c)) => c -> RLE (Elem c) encode = reduce-{-# RULES "encode/recode" encode = recode #-}-{-# RULES "encode/encodeList" encode = encodeList #-}++-- {-# RULES "encode/recode" encode = recode #-}+-- {-# RULES "encode/encodeList" encode = encodeList #-} decode :: RLE a -> [a] decode = reduce