timemap-0.0.1: A mutable hashmap, implicitly indexed by UTCTime.

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.

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

Adjusts the value at k, while updating its time.

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

Deletes the value at k.

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

Filter

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

filterWithKey :: (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