intern 0.4.0 → 0.5.0
raw patch · 14 files changed
+169/−159 lines, 14 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.ByteString.Interned: InternedByteString :: {-# UNPACK #-} !Id -> {-# UNPACK #-} !ByteString -> InternedByteString
- Data.ByteString.Interned: data InternedByteString
- 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.String.Interned: data InternedString
- 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.Interned.ByteString: data InternedByteString
+ Data.Interned.Internal: recover :: Interned t => Description t -> IO (Maybe t)
+ Data.Interned.Internal.ByteString: InternedByteString :: {-# UNPACK #-} !Id -> {-# UNPACK #-} !ByteString -> InternedByteString
+ Data.Interned.Internal.ByteString: data InternedByteString
+ Data.Interned.Internal.ByteString: instance Eq (Description InternedByteString)
+ Data.Interned.Internal.ByteString: instance Eq InternedByteString
+ Data.Interned.Internal.ByteString: instance Hashable (Description InternedByteString)
+ Data.Interned.Internal.ByteString: instance Interned InternedByteString
+ Data.Interned.Internal.ByteString: instance IsString InternedByteString
+ Data.Interned.Internal.ByteString: instance Ord InternedByteString
+ Data.Interned.Internal.ByteString: instance Show InternedByteString
+ Data.Interned.Internal.ByteString: instance Uninternable InternedByteString
+ Data.Interned.Internal.String: IS :: {-# UNPACK #-} !Id -> String -> InternedString
+ Data.Interned.Internal.String: data InternedString
+ Data.Interned.Internal.String: instance Eq (Description InternedString)
+ Data.Interned.Internal.String: instance Eq InternedString
+ Data.Interned.Internal.String: instance Hashable (Description InternedString)
+ Data.Interned.Internal.String: instance Interned InternedString
+ Data.Interned.Internal.String: instance IsString InternedString
+ Data.Interned.Internal.String: instance Ord InternedString
+ Data.Interned.Internal.String: instance Show InternedString
+ Data.Interned.Internal.String: instance Uninternable InternedString
+ Data.Interned.Internal.Text: InternedText :: {-# UNPACK #-} !Id -> {-# UNPACK #-} !Text -> InternedText
+ Data.Interned.Internal.Text: data InternedText
+ Data.Interned.Internal.Text: instance Eq (Description InternedText)
+ Data.Interned.Internal.Text: instance Eq InternedText
+ Data.Interned.Internal.Text: instance Hashable (Description InternedText)
+ Data.Interned.Internal.Text: instance Interned InternedText
+ Data.Interned.Internal.Text: instance IsString InternedText
+ Data.Interned.Internal.Text: instance Ord InternedText
+ Data.Interned.Internal.Text: instance Show InternedText
+ Data.Interned.Internal.Text: instance Uninternable InternedText
+ Data.Interned.String: data InternedString
+ Data.Interned.Text: data InternedText
Files
- Data/ByteString/Interned.hs +0/−6
- Data/ByteString/Interned/Internal.hs +0/−45
- Data/Interned/ByteString.hs +6/−0
- Data/Interned/Internal.hs +10/−0
- Data/Interned/Internal/ByteString.hs +45/−0
- Data/Interned/Internal/String.hs +47/−0
- Data/Interned/Internal/Text.hs +44/−0
- Data/Interned/String.hs +5/−0
- Data/Interned/Text.hs +5/−0
- Data/String/Interned.hs +0/−5
- Data/String/Interned/Internal.hs +0/−47
- Data/Text/Interned.hs +0/−5
- Data/Text/Interned/Internal.hs +0/−44
- intern.cabal +7/−7
− Data/ByteString/Interned.hs
@@ -1,6 +0,0 @@-module Data.ByteString.Interned- ( InternedByteString(..)- ) where--import Data.ByteString.Interned.Internal-
− Data/ByteString/Interned/Internal.hs
@@ -1,45 +0,0 @@-{-# 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/ByteString.hs view
@@ -0,0 +1,6 @@+module Data.Interned.ByteString+ ( InternedByteString+ ) where++import Data.Interned.Internal.ByteString+
Data/Interned/Internal.hs view
@@ -12,6 +12,7 @@ , cacheSize , Id , intern+ , recover ) where import Data.Hashable@@ -36,6 +37,7 @@ mkCache = result where result = Cache $ unsafePerformIO $ newMVar $ CacheState (seedIdentity result) HashMap.empty + type Id = Int class ( Eq (Description t)@@ -69,3 +71,11 @@ return (CacheState (i + 1) (HashMap.insert dt wt m), t) remove = modifyMVar_ (getCache cache) $ \ (CacheState i m) -> return $ CacheState i (HashMap.delete dt m)++-- given a description, go hunting for an entry in the cache+recover :: Interned t => Description t -> IO (Maybe t)+recover dt = do+ CacheState _ m <- readMVar $ getCache cache+ case HashMap.lookup dt m of+ Nothing -> return Nothing+ Just wt -> deRefWeak wt
+ Data/Interned/Internal/ByteString.hs view
@@ -0,0 +1,45 @@+{-# LANGUAGE TypeFamilies, FlexibleInstances #-}+module Data.Interned.Internal.ByteString+ ( 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/Internal/String.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE TypeFamilies, FlexibleInstances #-}+module Data.Interned.Internal.String+ ( 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/Interned/Internal/Text.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE TypeFamilies, FlexibleInstances #-}+module Data.Interned.Internal.Text+ ( 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 #-}
+ Data/Interned/String.hs view
@@ -0,0 +1,5 @@+module Data.Interned.String+ ( InternedString+ ) where++import Data.Interned.Internal.String
+ Data/Interned/Text.hs view
@@ -0,0 +1,5 @@+module Data.Interned.Text+ ( InternedText+ ) where++import Data.Interned.Internal.Text
− Data/String/Interned.hs
@@ -1,5 +0,0 @@-module Data.String.Interned- ( InternedString- ) where--import Data.String.Interned.Internal
− Data/String/Interned/Internal.hs
@@ -1,47 +0,0 @@-{-# 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
@@ -1,5 +0,0 @@-module Data.Text.Interned- ( InternedText- ) where--import Data.Text.Interned.Internal
− Data/Text/Interned/Internal.hs
@@ -1,44 +0,0 @@-{-# 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.4.0+version: 0.5.0 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -29,12 +29,12 @@ exposed-modules: Data.Interned+ Data.Interned.ByteString+ Data.Interned.String+ Data.Interned.Text Data.Interned.Internal- Data.ByteString.Interned- Data.ByteString.Interned.Internal- Data.String.Interned- Data.String.Interned.Internal- Data.Text.Interned- Data.Text.Interned.Internal+ Data.Interned.Internal.ByteString+ Data.Interned.Internal.String+ Data.Interned.Internal.Text ghc-options: -Wall