|
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 key val backendType cacheType | | type TFiniteMap key val backendType = TMap (FM key) key val backendType LRU | | 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) | | newTFiniteMapIO :: (Ord k, Backend k a b) => b k a -> IO (TFiniteMap k a b) | | lookup :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> stm (Maybe a) | | insert :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => k -> a -> TMap map k a b c -> stm () | | delete :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> stm () | | member :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> stm Bool | | adjust :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => (a -> a) -> k -> TMap map k a b c -> stm () | | purgeTMapIO :: (FiniteMapX map k, MonadIO io, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> io () | | getMaximumSize :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> stm (Maybe Int) | | setMaximumSize :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> Int -> stm () | | getCurrentSize :: (FiniteMapX map k, MonadAdvSTM stm, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> stm Int | | markAsDirty :: (FiniteMapX map k, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> IO () | | tryMarkAsDirty :: (FiniteMapX map k, Ord k, Backend k a b, CacheStructure c k) => k -> TMap map k a b c -> IO () | | flushBackend :: (FiniteMapX map k, Ord k, Backend k a b, CacheStructure c k) => TMap map k a b c -> IO () | | |
|
|
|
TMap Types
|
|
data TMap map key val backendType cacheType | Source |
|
The generic transactional map type.
|
|
|
type TFiniteMap key val backendType = TMap (FM key) key val backendType LRU | Source |
|
The standard library type Data.Map repackaged as a 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.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.
|
|
|
|
|
|
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.
|
|
Controlling 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).
|
|
|
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).
|
|
Backend Communication
|
|
|
Causes the element to be reread from the backend on the next lookup.
Throws an EntryNotFound exception if the entry does not exist.
|
|
|
Causes the element to be reread from the backend on the next lookup. Does
not throw an error when the element does not exist.
|
|
|
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 |