persistent-map-0.1.0: A thread-safe interface for finite map types with optional persistency support.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 k a b c
class HasKey a k | a -> k where
key :: a -> k
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
purgeTMap :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> m ()
purgeTMapIO :: (FiniteMapX map k, MonadIO m, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> m ()
Documentation
data TMap map k a b c Source
class HasKey a k | a -> k whereSource
Instantiated by types where values have a unique key.
Methods
key :: a -> kSource
show/hide Instances
HasKey Sometype Int
HasKey Sometype Int
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.TMap.CacheStructure.LRU

will use a binary-serialization backend for persistent storage and a "least recently used" caching algorithm.

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 Int) Int String BinaryBackend LRU)
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.
purgeTMap :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> m ()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). Warning: This function should always be called at the end of a transaction to prevent nonterminating retry-loops!
purgeTMapIO :: (FiniteMapX map k, MonadIO m, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> m ()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).
Produced by Haddock version 2.4.2