| persistent-map-0.1.0: A thread-safe interface for finite map types with optional persistency support. | Source code | Contents | Index |
|
Data.TStorage | Portability | non-portable (requires STM) | Stability | experimental | Maintainer | Peter 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 | | | 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 |
|
|
|
class HasKey a k | a -> k where | Source |
|
Instantiated by types where values have a unique key.
| | Methods | | | Instances | |
|
|
|
:: (FiniteMapX map k, Ord k, Backend k a b, CacheStructure c k) | | => b k a | the backend
| -> Maybe Int | maximum-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)
|
|
|
|
Adds a new element to the map. The key is automatically deduced by the
HasKey instantiation.
|
|
|
Tries to fill a partially initialized value with data from the TMap. Returns
Nothing if the TMap does not contain a corresponding entry.
|
|
|
Fills a partially initialized value with data from the TMap. Throws
an EntryNotFound exception if there is no corresponding entry.
|
|
|
Removes the element from the map.
|
|
|
Removes the entry that has the supplied key.
|
|
|
Applies a function to an element that might be only partially initialized.
|
|
|
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!
|
|
|
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 |