timemap-0.0.7

Copyright(c) 2015 Athan Clark
LicenseBSD-3
Maintainerathan.clark@gmail.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

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.

Synopsis

Types

data TimeMap k a Source #

A mutable reference for a time-indexed map, similar to a STRef.

Construction

newTimeMap :: STM (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.

insertWithTime :: forall k a. Hashable k => Eq k => UTCTime -> k -> a -> TimeMap k a -> STM () Source #

update :: Hashable k => Eq k => (a -> Maybe a) -> k -> TimeMap k a -> IO () Source #

Updates or deletes the value at k, while updating its time.

updateWithTime :: forall k a. Hashable k => Eq k => UTCTime -> (a -> Maybe a) -> k -> TimeMap k a -> STM () Source #

adjust :: Hashable k => Eq k => (a -> a) -> k -> TimeMap k a -> IO () Source #

Adjusts the value at k, while updating its time.

adjustWithTime :: forall k a. Hashable k => Eq k => UTCTime -> (a -> a) -> k -> TimeMap k a -> STM () Source #

delete :: Hashable k => Eq k => k -> TimeMap k a -> STM () Source #

Deletes the value at k.

touch :: Hashable k => Eq k => k -> TimeMap k a -> IO () Source #

Resets the key to the current time, and fails silently when the key isn't present.

Query

lookup :: Hashable k => Eq k => k -> TimeMap k a -> STM (Maybe a) Source #

Performs a non-mutating lookup for some key.

timeOf :: Hashable k => Eq k => k -> TimeMap k a -> STM (Maybe UTCTime) Source #

ageOf :: Hashable k => Eq k => k -> TimeMap k a -> IO (Maybe NominalDiffTime) Source #

keys :: Hashable k => Eq k => TimeMap k a -> STM (HashSet k) Source #

elems :: TimeMap k a -> STM [a] Source #

toList :: Hashable k => Eq k => TimeMap k a -> STM [(k, a)] Source #

Filter

filter :: Hashable k => Eq k => (a -> Bool) -> TimeMap k a -> STM () Source #

filterWithKey :: forall k a. Hashable k => Eq k => (k -> a -> Bool) -> TimeMap k a -> STM () Source #

filterSince :: Hashable k => Eq k => UTCTime -> TimeMap k a -> STM () Source #

Filters out all entries older than or equal to a designated time

filterFromNow Source #

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

Take

takeSince :: Hashable k => Eq k => UTCTime -> TimeMap k a -> STM [(k, a)] Source #

takeFromNow :: Hashable k => Eq k => NominalDiffTime -> TimeMap k a -> IO [(k, a)] Source #