persistent-map-0.3.5: A thread-safe (STM) persistency interface for finite map types.Source codeContentsIndex
Data.TStorage
Portabilitynon-portable (requires STM)
Stabilityexperimental
MaintainerPeter Robinson <thaldyron@gmail.com>
Description

Provides a high level interface to Data.TMap. This module was inspired by the TCache package, (C) Alberto Gomez Corona.

The essential difference to the low level functions in Data.TMap is that this interface assumes that the stored type is an instance of HasKey, allowing partially filled (i.e. complete enough for deducing the key) values to be passed to the interface functions.

Synopsis
data TMap map key val backendType cacheType
newTMapIO :: (FiniteMapX map k, Ord k, Backend k a b, CacheStructure c k) => b k a -> Maybe Int -> IO (TMap map k a b c)
add :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm ()
tryComplete :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm (Maybe a)
complete :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm a
remove :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm ()
removeByKey :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => k -> TMap map k a b c -> stm ()
apply :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => (a -> a) -> a -> TMap map k a b c -> stm a
purgeTMapIO :: (FiniteMapX map k, MonadIO io, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> io ()
class HasKey a k | a -> k where
key :: a -> k
Documentation
data TMap map key val backendType cacheType Source
The generic transactional map type.
newTMapIOSource
:: (FiniteMapX map k, Ord k, Backend k a b, CacheStructure c k)
=> b k athe backend
-> Maybe Intmaximum-size: Use Nothing for unbounded size.
-> IO (TMap map k a b c)

Creates a new TMap. You will need to use an apropriate backend and specify the caching policy, e.g.,

   import Data.TMap.Backend.Binary( BinaryBackend,mkBinaryBackend )
   import Data.CacheStructure.LRU(LRU)

will use a binary-serialization backend for persistent storage and a "least recently used" caching algorithm. See newTFiniteMapIO for a less generic construction method.

Now, to create an unbounded map that uses the 'FM Int String' (see package EdisonCore) as the map type, you can write

   backend <- mkBinaryBackend "myworkdir" "mytempdir"
   tmap <- newTMapIO backend Nothing :: IO (TMap (FM.FM key) key val BinaryBackend LRU)

Note that newTFiniteMapIO provides an easier construction method. See file Sample.hs for further examples.

add :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm ()Source
Adds a new element to the map. The key is automatically deduced by the HasKey instantiation.
tryComplete :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm (Maybe a)Source
Tries to fill a partially initialized value with data from the TMap. Returns Nothing if the TMap does not contain a corresponding entry.
complete :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm aSource
Fills a partially initialized value with data from the TMap. Throws an EntryNotFound exception if there is no corresponding entry.
remove :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> stm ()Source
Removes the element from the map.
removeByKey :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => k -> TMap map k a b c -> stm ()Source
Removes the entry that has the supplied key.
apply :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => (a -> a) -> a -> TMap map k a b c -> stm aSource
Applies a function to an element that might be only partially initialized.
purgeTMapIO :: (FiniteMapX map k, MonadIO io, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> io ()Source
Reduces the map to the appropriate size if the maximum size was exceeded. Calls Data.TMap.Backend.flush if the map is purged. Runs in O(1) if the map size is within bounds, otherwise O(n).
class HasKey a k | a -> k whereSource
Types where values have a key for indexing.
Methods
key :: a -> kSource
show/hide Instances
HasKey Sometype Int
HasKey Sometype Int
Produced by Haddock version 2.4.2