|
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 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 | |
|
|
Documentation |
|
data TMap map key val backendType cacheType | Source |
|
The generic transactional map type.
|
|
|
|
:: (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.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.
|
|
|
|
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).
|
|
class HasKey a k | a -> k where | Source |
|
Types where values have a key for indexing.
| | Methods | | | Instances | |
|
|
Produced by Haddock version 2.4.2 |