-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Sharing for the binary package
--   
--   I had problems with the size of the allocated heap space after
--   serializing and loading data with the binary package. The reason was
--   that binary does not support sharing of identical elements, so I came
--   up with the generic solution in this package.
@package binary-shared
@version 0.8.3


-- | Binary serializing with sharing
module Data.Binary.Shared

-- | A class for storing Binary instances with shared nodes. Cycles are not
--   supported, cause put and get is a one path process.
class (Typeable alpha, Ord alpha, Eq alpha, Show alpha) => BinaryShared alpha where putShared fput v = do { (dict, unique) <- get; case (ObjC v) `lookup` dict of { Just i -> lift (putWord8 0 >> putWord64be (fromIntegral i)) Nothing -> do { put (dict, unique + 1); lift (putWord8 1); lift (putWord64be (fromIntegral unique)); fput v; (dict2, unique2) <- get; let newDict = insert (ObjC v) unique dict2; put (newDict, unique2) } } } getShared f = do { dict <- get; w <- lift getWord8; case w of { 0 -> do { i <- lift (liftM fromIntegral (getWord64be)); case lookup i dict of { Just (ObjC obj) -> return (forceJust (cast obj) "Shared>>getShared: Cast failed") Nothing -> error $ "Shared>>getShared : Dont find in Map " ++ show i } } 1 -> do { i <- lift (liftM fromIntegral (getWord64be)); obj <- f; dict2 <- get; put (insert i (ObjC obj) dict2); return obj } _ -> error $ "Shared>>getShared : Encoding error" } }

-- | Encode a value in the Put monad.
put :: BinaryShared alpha => alpha -> PutShared
putShared :: BinaryShared alpha => (alpha -> PutShared) -> alpha -> PutShared

-- | Decode a value in the Get monad
get :: BinaryShared alpha => GetShared alpha
getShared :: BinaryShared alpha => GetShared alpha -> GetShared alpha
encodeFileSer :: BinaryShared a => FilePath -> a -> IO ()
encodeSer :: BinaryShared a => a -> ByteString
decodeSer :: BinaryShared alpha => ByteString -> alpha
instance GHC.Classes.Eq Data.Binary.Shared.Object
instance GHC.Classes.Ord Data.Binary.Shared.Object
instance Data.Binary.Shared.BinaryShared a => Data.Binary.Shared.BinaryShared [a]
instance Data.Binary.Shared.BinaryShared a => Data.Binary.Shared.BinaryShared (GHC.Base.Maybe a)
instance (Data.Binary.Shared.BinaryShared a, Data.Binary.Shared.BinaryShared b) => Data.Binary.Shared.BinaryShared (a, b)
instance Data.Binary.Shared.BinaryShared a => Data.Binary.Shared.BinaryShared (Data.Set.Base.Set a)
instance (Data.Binary.Shared.BinaryShared k, Data.Binary.Shared.BinaryShared e) => Data.Binary.Shared.BinaryShared (Data.Map.Base.Map k e)
instance Data.Binary.Shared.BinaryShared GHC.Types.Bool
instance Data.Binary.Shared.BinaryShared GHC.Types.Char
instance Data.Binary.Shared.BinaryShared GHC.Types.Int
instance Data.Binary.Shared.BinaryShared GHC.Integer.Type.Integer
instance Data.Binary.Shared.BinaryShared Data.ByteString.Internal.ByteString
