| Copyright | (c) 2015 Athan Clark |
|---|---|
| License | BSD-3 |
| Maintainer | athan.clark@gmail.com |
| Stability | experimental |
| Portability | GHC |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.TimeMap
Contents
Description
A time-indexed mutable map for hashable keys.
The goal of this map is to provide moderately fast lookups and insertions for
key/value pairs, while implicitly keeping track of the last modification time of
each entity. The auxilliary time data is used for filterSince and filterFromNow,
which quickly prune the data set to get rid of old entities.
- data TimeMap k a
- newTimeMap :: IO (TimeMap k a)
- insert :: (Hashable k, Eq k) => k -> a -> TimeMap k a -> IO ()
- adjust :: (Hashable k, Eq k) => (a -> a) -> k -> TimeMap k a -> IO ()
- delete :: (Hashable k, Eq k) => k -> TimeMap k a -> IO ()
- lookup :: (Hashable k, Eq k) => k -> TimeMap k a -> IO (Maybe a)
- filterSince :: (Hashable k, Eq k) => UTCTime -> TimeMap k a -> IO ()
- filterFromNow :: (Hashable k, Eq k) => NominalDiffTime -> TimeMap k a -> IO ()
Types
Construction
newTimeMap :: IO (TimeMap k a) Source
Create a fresh, empty map.
insert :: (Hashable k, Eq k) => k -> a -> TimeMap k a -> IO () Source
Inserts a key and value into a TimeMap - it adds the value
or overwites an existing entity.
adjust :: (Hashable k, Eq k) => (a -> a) -> k -> TimeMap k a -> IO () Source
Adjusts the value at k, while updating its time.
Query
lookup :: (Hashable k, Eq k) => k -> TimeMap k a -> IO (Maybe a) Source
Performs a non-mutating lookup for some key.
Filter
filterSince :: (Hashable k, Eq k) => UTCTime -> TimeMap k a -> IO () Source
Filters out all entries older than or equal to a designated time
Arguments
| :: (Hashable k, Eq k) | |
| => NominalDiffTime | Assumes a positive distance into the past |
| -> TimeMap k a | |
| -> IO () |
Filters out all entries within some time frame
filterFromNow 1 -- removes entities older than or equal to one second from now