intern 0.2.2.1 → 0.3.0
raw patch · 9 files changed
+158/−98 lines, 9 filesdep +textPVP ok
version bump matches the API change (PVP)
Dependencies added: text
API changes (from Hackage documentation)
- Data.ByteString.Interned: instance Eq (Description InternedByteString)
- Data.ByteString.Interned: instance Eq InternedByteString
- Data.ByteString.Interned: instance Hashable (Description InternedByteString)
- Data.ByteString.Interned: instance Interned InternedByteString
- Data.ByteString.Interned: instance IsString InternedByteString
- Data.ByteString.Interned: instance Ord InternedByteString
- Data.ByteString.Interned: instance Show InternedByteString
- Data.ByteString.Interned: instance Uninternable InternedByteString
- Data.Interned: Id :: Int -> Id t
- Data.Interned: newtype Id t
- Data.Interned.Internal: Id :: Int -> Id t
- Data.Interned.Internal: instance Enum (Id t)
- Data.Interned.Internal: instance Eq (Id t)
- Data.Interned.Internal: instance Hashable (Id t)
- Data.Interned.Internal: instance Integral (Id t)
- Data.Interned.Internal: instance Num (Id t)
- Data.Interned.Internal: instance Ord (Id t)
- Data.Interned.Internal: instance Real (Id t)
- Data.Interned.Internal: instance Show (Id t)
- Data.Interned.Internal: newtype Id t
- Data.String.Interned: IS :: {-# UNPACK #-} !Id InternedString -> String -> InternedString
- Data.String.Interned: instance Eq (Description InternedString)
- Data.String.Interned: instance Eq InternedString
- Data.String.Interned: instance Hashable (Description InternedString)
- Data.String.Interned: instance Interned InternedString
- Data.String.Interned: instance IsString InternedString
- Data.String.Interned: instance Ord InternedString
- Data.String.Interned: instance Show InternedString
- Data.String.Interned: instance Uninternable InternedString
+ Data.ByteString.Interned.Internal: InternedByteString :: {-# UNPACK #-} !Id -> {-# UNPACK #-} !ByteString -> InternedByteString
+ Data.ByteString.Interned.Internal: data InternedByteString
+ Data.ByteString.Interned.Internal: instance Eq (Description InternedByteString)
+ Data.ByteString.Interned.Internal: instance Eq InternedByteString
+ Data.ByteString.Interned.Internal: instance Hashable (Description InternedByteString)
+ Data.ByteString.Interned.Internal: instance Interned InternedByteString
+ Data.ByteString.Interned.Internal: instance IsString InternedByteString
+ Data.ByteString.Interned.Internal: instance Ord InternedByteString
+ Data.ByteString.Interned.Internal: instance Show InternedByteString
+ Data.ByteString.Interned.Internal: instance Uninternable InternedByteString
+ Data.Interned: type Id = Int
+ Data.Interned.Internal: type Id = Int
+ Data.String.Interned.Internal: IS :: {-# UNPACK #-} !Id -> String -> InternedString
+ Data.String.Interned.Internal: data InternedString
+ Data.String.Interned.Internal: instance Eq (Description InternedString)
+ Data.String.Interned.Internal: instance Eq InternedString
+ Data.String.Interned.Internal: instance Hashable (Description InternedString)
+ Data.String.Interned.Internal: instance Interned InternedString
+ Data.String.Interned.Internal: instance IsString InternedString
+ Data.String.Interned.Internal: instance Ord InternedString
+ Data.String.Interned.Internal: instance Show InternedString
+ Data.String.Interned.Internal: instance Uninternable InternedString
+ Data.Text.Interned: data InternedText
+ Data.Text.Interned.Internal: InternedText :: {-# UNPACK #-} !Id -> {-# UNPACK #-} !Text -> InternedText
+ Data.Text.Interned.Internal: data InternedText
+ Data.Text.Interned.Internal: instance Eq (Description InternedText)
+ Data.Text.Interned.Internal: instance Eq InternedText
+ Data.Text.Interned.Internal: instance Hashable (Description InternedText)
+ Data.Text.Interned.Internal: instance Interned InternedText
+ Data.Text.Interned.Internal: instance IsString InternedText
+ Data.Text.Interned.Internal: instance Ord InternedText
+ Data.Text.Interned.Internal: instance Show InternedText
+ Data.Text.Interned.Internal: instance Uninternable InternedText
- Data.ByteString.Interned: InternedByteString :: {-# UNPACK #-} !Id InternedByteString -> {-# UNPACK #-} !ByteString -> InternedByteString
+ Data.ByteString.Interned: InternedByteString :: {-# UNPACK #-} !Id -> {-# UNPACK #-} !ByteString -> InternedByteString
- Data.Interned: identify :: Interned t => Id t -> Uninterned t -> t
+ Data.Interned: identify :: Interned t => Id -> Uninterned t -> t
- Data.Interned: identity :: Interned t => t -> Id t
+ Data.Interned: identity :: Interned t => t -> Id
- Data.Interned.Internal: CacheState :: {-# UNPACK #-} !Id t -> !HashMap (Description t) (Weak t) -> CacheState t
+ Data.Interned.Internal: CacheState :: {-# UNPACK #-} !Id -> !HashMap (Description t) (Weak t) -> CacheState t
- Data.Interned.Internal: identify :: Interned t => Id t -> Uninterned t -> t
+ Data.Interned.Internal: identify :: Interned t => Id -> Uninterned t -> t
- Data.Interned.Internal: identity :: Interned t => t -> Id t
+ Data.Interned.Internal: identity :: Interned t => t -> Id
Files
- Data/ByteString/Interned.hs +1/−41
- Data/ByteString/Interned/Internal.hs +45/−0
- Data/Interned.hs +1/−1
- Data/Interned/Internal.hs +5/−9
- Data/String/Interned.hs +2/−44
- Data/String/Interned/Internal.hs +47/−0
- Data/Text/Interned.hs +5/−0
- Data/Text/Interned/Internal.hs +44/−0
- intern.cabal +8/−3
Data/ByteString/Interned.hs view
@@ -1,46 +1,6 @@-{-# LANGUAGE TypeFamilies, FlexibleInstances #-} module Data.ByteString.Interned ( InternedByteString(..) ) where -import Data.String-import Data.Interned-import Data.ByteString-import Data.ByteString.Char8 as Char8-import Data.Hashable-import Data.Function (on)--data InternedByteString = InternedByteString - {-# UNPACK #-} !(Id InternedByteString)- {-# UNPACK #-} !ByteString--instance IsString InternedByteString where- fromString = intern . Char8.pack--instance Eq InternedByteString where- (==) = (==) `on` identity--instance Ord InternedByteString where- compare = compare `on` identity--instance Show InternedByteString where- showsPrec d (InternedByteString _ b) = showsPrec d b--instance Interned InternedByteString where- type Uninterned InternedByteString = ByteString- data Description InternedByteString = DBS {-# UNPACK #-} !ByteString- deriving (Eq) - describe = DBS- identify = InternedByteString- identity (InternedByteString i _) = i- cache = ibsCache--instance Uninternable InternedByteString where- unintern (InternedByteString _ b) = b --instance Hashable (Description InternedByteString) where- hash (DBS h) = hash h+import Data.ByteString.Interned.Internal -ibsCache :: Cache InternedByteString-ibsCache = mkCache-{-# NOINLINE ibsCache #-}
+ Data/ByteString/Interned/Internal.hs view
@@ -0,0 +1,45 @@+{-# LANGUAGE TypeFamilies, FlexibleInstances #-}+module Data.ByteString.Interned.Internal+ ( InternedByteString(..)+ ) where++import Data.String+import Data.Interned+import Data.ByteString+import Data.ByteString.Char8 as Char8+import Data.Hashable+import Data.Function (on)++data InternedByteString = InternedByteString + {-# UNPACK #-} !Id+ {-# UNPACK #-} !ByteString++instance IsString InternedByteString where+ fromString = intern . Char8.pack++instance Eq InternedByteString where+ (==) = (==) `on` identity++instance Ord InternedByteString where+ compare = compare `on` identity++instance Show InternedByteString where+ showsPrec d (InternedByteString _ b) = showsPrec d b++instance Interned InternedByteString where+ type Uninterned InternedByteString = ByteString+ data Description InternedByteString = DBS {-# UNPACK #-} !ByteString deriving (Eq) + describe = DBS+ identify = InternedByteString+ identity (InternedByteString i _) = i+ cache = ibsCache++instance Uninternable InternedByteString where+ unintern (InternedByteString _ b) = b ++instance Hashable (Description InternedByteString) where+ hash (DBS h) = hash h++ibsCache :: Cache InternedByteString+ibsCache = mkCache+{-# NOINLINE ibsCache #-}
Data/Interned.hs view
@@ -4,7 +4,7 @@ , mkCache , Cache , cacheSize- , Id(..)+ , Id , intern ) where
Data/Interned/Internal.hs view
@@ -10,7 +10,7 @@ , Cache(..) , CacheState(..) , cacheSize- , Id(..)+ , Id , intern ) where @@ -22,7 +22,7 @@ import System.Mem.Weak data CacheState t = CacheState - {-# UNPACK #-} !(Id t) + {-# UNPACK #-} !Id !(HashMap (Description t) (Weak t)) newtype Cache t = Cache { getCache :: MVar (CacheState t) }@@ -35,11 +35,7 @@ mkCache :: Cache t mkCache = Cache $ unsafePerformIO $ newMVar $ CacheState 0 HashMap.empty -newtype Id t = Id Int deriving (Eq,Ord,Show,Num,Real,Integral,Enum)--instance Hashable (Id t) where- hash (Id t) = hash t- hashWithSalt s (Id t) = hashWithSalt s t+type Id = Int class ( Eq (Description t) , Hashable (Description t)@@ -47,8 +43,8 @@ data Description t type Uninterned t describe :: Uninterned t -> Description t - identify :: Id t -> Uninterned t -> t- identity :: t -> Id t+ identify :: Id -> Uninterned t -> t+ identity :: t -> Id cache :: Cache t class Interned t => Uninternable t where
Data/String/Interned.hs view
@@ -1,47 +1,5 @@-{-# LANGUAGE TypeFamilies, FlexibleInstances #-} module Data.String.Interned- ( InternedString(..)+ ( InternedString ) where -import Data.String-import Data.Interned-import Data.Hashable-import Data.Foldable-import Data.Function (on)--data InternedString = IS - {-# UNPACK #-} !(Id InternedString)- String--instance IsString InternedString where- fromString = intern--instance Eq InternedString where- (==) = (==) `on` identity--instance Ord InternedString where- compare = compare `on` identity--instance Show InternedString where- showsPrec d (IS _ b) = showsPrec d b--instance Interned InternedString where- type Uninterned InternedString = String- data Description InternedString = Cons {-# UNPACK #-} !Char String | Nil- deriving (Eq) - describe (c:cs) = Cons c cs- describe [] = Nil- identify = IS- identity (IS i _) = i- cache = stringCache--instance Uninternable InternedString where- unintern (IS _ b) = b --instance Hashable (Description InternedString) where- hash (Cons c s) = foldl' hashWithSalt (hashWithSalt 0 c) s- hash Nil = 0--stringCache :: Cache InternedString-stringCache = mkCache-{-# NOINLINE stringCache #-}+import Data.String.Interned.Internal
+ Data/String/Interned/Internal.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE TypeFamilies, FlexibleInstances #-}+module Data.String.Interned.Internal+ ( InternedString(..)+ ) where++import Data.String+import Data.Interned+import Data.Hashable+import Data.Foldable+import Data.Function (on)++data InternedString = IS + {-# UNPACK #-} !Id+ String++instance IsString InternedString where+ fromString = intern++instance Eq InternedString where+ (==) = (==) `on` identity++instance Ord InternedString where+ compare = compare `on` identity++instance Show InternedString where+ showsPrec d (IS _ b) = showsPrec d b++instance Interned InternedString where+ type Uninterned InternedString = String+ data Description InternedString = Cons {-# UNPACK #-} !Char String | Nil+ deriving (Eq) + describe (c:cs) = Cons c cs+ describe [] = Nil+ identify = IS+ identity (IS i _) = i+ cache = stringCache++instance Uninternable InternedString where+ unintern (IS _ b) = b ++instance Hashable (Description InternedString) where+ hash (Cons c s) = foldl' hashWithSalt (hashWithSalt 0 c) s+ hash Nil = 0++stringCache :: Cache InternedString+stringCache = mkCache+{-# NOINLINE stringCache #-}
+ Data/Text/Interned.hs view
@@ -0,0 +1,5 @@+module Data.Text.Interned+ ( InternedText+ ) where++import Data.Text.Interned.Internal
+ Data/Text/Interned/Internal.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE TypeFamilies, FlexibleInstances #-}+module Data.Text.Interned.Internal+ ( InternedText(..)+ ) where++import Data.String+import Data.Interned+import Data.Text+import Data.Hashable+import Data.Function (on)++data InternedText = InternedText + {-# UNPACK #-} !Id+ {-# UNPACK #-} !Text++instance IsString InternedText where+ fromString = intern . pack++instance Eq InternedText where+ (==) = (==) `on` identity++instance Ord InternedText where+ compare = compare `on` identity++instance Show InternedText where+ showsPrec d (InternedText _ b) = showsPrec d b++instance Interned InternedText where+ type Uninterned InternedText = Text+ data Description InternedText = DT {-# UNPACK #-} !Text deriving (Eq) + describe = DT+ identify = InternedText+ identity (InternedText i _) = i+ cache = itCache++instance Uninternable InternedText where+ unintern (InternedText _ b) = b ++instance Hashable (Description InternedText) where+ hash (DT h) = hash h++itCache :: Cache InternedText+itCache = mkCache+{-# NOINLINE itCache #-}
intern.cabal view
@@ -1,6 +1,6 @@ name: intern category: Data, Data Structures-version: 0.2.2.1+version: 0.3.0 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -23,13 +23,18 @@ build-depends: base >= 4 && < 5, bytestring >= 0.9.1 && < 0.10,- unordered-containers >= 0.1.4 && < 0.2,- hashable >= 1.1.2 && < 1.2+ text >= 0.11.1.5 && < 0.12,+ hashable >= 1.1.2 && < 1.2,+ unordered-containers >= 0.1.4 && < 0.2 exposed-modules: Data.Interned Data.Interned.Internal Data.ByteString.Interned+ Data.ByteString.Interned.Internal Data.String.Interned+ Data.String.Interned.Internal+ Data.Text.Interned+ Data.Text.Interned.Internal ghc-options: -Wall