packages feed

hblock 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+49/−32 lines, 3 files

Files

Data/Indexation/Constraints.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE RankNTypes, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}+{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE TemplateHaskell #-} module Data.Indexation.Constraints     ( Text128     , Text256@@ -35,6 +38,24 @@ newtype Text2048 = Text2048 T.Text deriving(Eq, Data, Ord, Read, Show, Typeable, IsString, Monoid, NFData) newtype Text4096 = Text4096 T.Text deriving(Eq, Data, Ord, Read, Show, Typeable, IsString, Monoid, NFData) +t128 :: T.Text -> Text128+t128 = Text128 . T.take 128++t256 :: T.Text -> Text256+t256 = Text256 . T.take 256++t512 :: T.Text -> Text512+t512 = Text512 . T.take 512 ++t1024 :: T.Text -> Text1024+t1024 = Text1024 . T.take 1024++t2048 :: T.Text -> Text2048+t2048 = Text2048 . T.take 2048++t4096 :: T.Text -> Text4096+t4096 = Text4096 . T.take 4096+ class TextConstraint a where     txtConstraint :: T.Text -> a     getTxt :: a -> T.Text@@ -62,6 +83,13 @@                  Just a -> getTxt a                  Nothing -> T.empty +$(deriveSafeCopy 0 'base ''Text128)+$(deriveSafeCopy 0 'base ''Text256)+$(deriveSafeCopy 0 'base ''Text512)+$(deriveSafeCopy 0 'base ''Text1024)+$(deriveSafeCopy 0 'base ''Text2048)+$(deriveSafeCopy 0 'base ''Text4096)+ instance Hashable Text128 where hashWithSalt s d = hashWithSalt s (getTxt d) instance Hashable Text256 where hashWithSalt s d = hashWithSalt s (getTxt d) instance Hashable Text512 where hashWithSalt s d = hashWithSalt s (getTxt d)@@ -82,19 +110,6 @@ instance Serialize Text4096 where put (Text4096 t) = put $ encodeUtf8 t                                   get = (Text4096 . decodeUtf8) `fmap` get -instance SafeCopy Text128 where putCopy (Text128 t) = putCopy t-                                getCopy = contain $ Text128 `fmap` safeGet-instance SafeCopy Text256 where putCopy (Text256 t) = putCopy t-                                getCopy = contain $ Text256 `fmap` safeGet-instance SafeCopy Text512 where putCopy (Text512 t) = putCopy t-                                getCopy = contain $ Text512 `fmap` safeGet-instance SafeCopy Text1024 where putCopy (Text1024 t) = putCopy t-                                 getCopy = contain $ Text1024 `fmap` safeGet-instance SafeCopy Text2048 where putCopy (Text2048 t) = putCopy t-                                 getCopy = contain $ Text2048 `fmap` safeGet-instance SafeCopy Text4096 where putCopy (Text4096 t) = putCopy t-                                 getCopy = contain $ Text4096 `fmap` safeGet- instance FromJSON Text128 where parseJSON (Aeson.String s) = return $ t128 s                                 parseJSON _ = mzero instance FromJSON Text256 where parseJSON (Aeson.String s) = return $ t256 s@@ -114,21 +129,4 @@ instance ToJSON Text2048 where toJSON s = Aeson.String (getTxt s) instance ToJSON Text4096 where toJSON s = Aeson.String (getTxt s) -t128 :: T.Text -> Text128-t128 = Text128 . T.take 128--t256 :: T.Text -> Text256-t256 = Text256 . T.take 256--t512 :: T.Text -> Text512-t512 = Text512 . T.take 512 --t1024 :: T.Text -> Text1024-t1024 = Text1024 . T.take 1024--t2048 :: T.Text -> Text2048-t2048 = Text2048 . T.take 2048--t4096 :: T.Text -> Text4096-t4096 = Text4096 . T.take 4096 
Data/Indexation/SimpleIx.hs view
@@ -23,6 +23,7 @@ , member , adjust , update+, adjustWithElement ) where  import Data.HashMap.Strict (HashMap)@@ -401,6 +402,24 @@        -> Maybe (Indexed a i1 i2 i3 i4) update i p a = adjust i p (const a) {-# INLINABLE update #-}++adjustWithElement :: ( Eq a+                     , Eq i1, Hashable i1, Eq i2, Hashable i2+                     , Eq i3, Hashable i3, Eq i4, Hashable i4+                     )+                  => Indexed a i1 i2 i3 i4 -> Int -> (a -> a) +                  -> Maybe (Indexed a i1 i2 i3 i4, a)+adjustWithElement (Indexed d a iis vf vi is s) pos f = do+    e <- me+    let newe = f e+    return (Indexed newdata a (_updateI iis pos e newe) vf +                              (_updateF vf vi pos e newe) is s+           , newe)+    where+        (me, newdata) = IM.updateLookupWithKey (\_ v -> Just $ f v) pos d+{-# INLINABLE adjustWithElement #-}++  instance ( SafeCopy a, Eq a,  SimpleIx a          , Eq i1, Hashable i1, Eq i2, Hashable i2, Eq i3, Hashable i3
hblock.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                hblock-version:             0.1.0.0+version:             0.1.0.1 synopsis:            A mutable vector that provides indexation on the datatype fields it stores -- description:          license:             BSD3