-- 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.2 -- | 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" } } put :: BinaryShared alpha => alpha -> PutShared putShared :: BinaryShared alpha => (alpha -> PutShared) -> alpha -> PutShared 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 BinaryShared ByteString instance BinaryShared Integer instance BinaryShared Int instance BinaryShared Char instance BinaryShared Bool instance (BinaryShared k, BinaryShared e) => BinaryShared (Map k e) instance BinaryShared a => BinaryShared (Set a) instance (BinaryShared a, BinaryShared b) => BinaryShared (a, b) instance BinaryShared a => BinaryShared (Maybe a) instance BinaryShared a => BinaryShared [a] instance Ord Object instance Eq Object