| persistent-map-0.1.0: A thread-safe interface for finite map types with optional persistency support. | Source code | Contents | Index |
|
Data.TMap | Portability | non-portable (requires STM) | Stability | experimental | Maintainer | Peter Robinson <thaldyron@gmail.com> |
|
|
|
|
|
Description |
Provides a thread-safe STM interface for finite map types with optional persistent
storage.
|
|
Synopsis |
|
data TMap map k a b c | | 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) | | lookup :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> m (Maybe a) | | insert :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => k -> a -> TMap map k a b c -> m () | | delete :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> m () | | member :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> m Bool | | adjust :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => (a -> a) -> k -> TMap map k a b c -> m () | | 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 () | | getMaximumSize :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> m (Maybe Int) | | setMaximumSize :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> Int -> m () | | getCurrentSize :: (FiniteMapX map k, MonadAdvSTM m, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> m Int | | flushBackend :: (FiniteMapX map k, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> IO () | | |
|
|
|
TMap
|
|
|
|
Creating a new TMap
|
|
|
:: (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)
|
|
|
Finite Map Interace
|
|
|
Looks for a given key in the map and (if necessary) in the persistent storage
and updates the map if necessary.
|
|
|
Adds a key-value mapping to the map. Can throw a DuplicateEntry
exception.
|
|
|
Removes a key from the map. Can throw an EntryNotFound exception.
|
|
|
Checks whether the given key is in the map.
|
|
|
Applies a function to the element identified by the key. Can throw an EntryNotFound exception.
|
|
Handling the size of the TMap
|
|
|
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).
|
|
|
Gets the maximum size of the map. O(1).
|
|
|
Sets the maximum size of the map. O(1). Note that the size of the TMap needs
to be reduced manually to the maximum size by calling purgeTMap.
|
|
|
Gets the current size of the map. O(1).
|
|
Flushing the backend
|
|
|
Sends a B.flush request to the backend. Useful for asynchronous backend
implementations.
|
|
Exception Type
|
|
|
Constructors | DuplicateEntry | | EntryNotFound | | TMapDefaultExc String | | BackendException String | |
| Instances | |
|
|
Produced by Haddock version 2.4.2 |