persistent-map-0.0.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 m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m ()
tryComplete :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m (Maybe a)
complete :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m a
remove :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m ()
removeKey :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => k -> TMap map k a b c -> m ()
apply :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => (a -> a) -> a -> TMap map k a b c -> m 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.StdoutBackend( newStdoutBackend )
   import Data.TMap.CacheStructure.LRU

will simply log all backend operations to Stdout and use a "least recently used" cache algorithm.

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

   tmap = newTMapIO newStdoutBackend Nothing :: IO (TMap (FM Int) Int String StdoutBackend LRU)
add :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m ()Source
Adds a new element to the map. The key is automatically deduced by the HasKey instantiation.
tryComplete :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m (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 m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m aSource
Fills a partially initialized value with data from the TMap. Throws a TMapNotFound exception if there is no corresponding entry.
remove :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => a -> TMap map k a b c -> m ()Source
Removes the element from the map.
removeKey :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => k -> TMap map k a b c -> m ()Source
Removes the entry that has the supplied key.
apply :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k, HasKey a k) => (a -> a) -> a -> TMap map k a b c -> m 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