netwire-3.1.0: Fast generic automaton arrow transformer for AFRP

MaintainerErtugrul Soeylemez <es@ertes.de>

Control.Wire.TimedMap

Contents

Description

This module implements a map, where each key has a timestamp. It maintains a timestamp index allowing you delete oldest entries quickly.

Synopsis

Timed map

data TimedMap t k a Source

A timed map is a regular map with timestamps and a timestamp index.

Constructors

TimedMap 

Fields

tmMap :: Map k (a, t)

Underlying map with timestamps.

tmTimes :: Map t (Set k)

Timestamp index.

Instances

(Show t, Show k, Show a) => Show (TimedMap t k a) 

Operations

Construct

tmEmpty :: TimedMap t k aSource

The empty timed map.

Read

tmFindWithDefaultSource

Arguments

:: Ord k 
=> a

Default, if key is not found.

-> k

Key to look up.

-> TimedMap t k a

Map to query.

-> a

Retrieved or default value.

Find a value with default.

tmLookup :: Ord k => k -> TimedMap t k a -> Maybe aSource

Look up the value for the given key.

Modify

tmInsertSource

Arguments

:: (Ord k, Ord t) 
=> t

Timestamp.

-> k

Key.

-> a

Value.

-> TimedMap t k a

Original map.

-> TimedMap t k a

Map with the value added.

Insert a value into the map.

tmLimitAge :: (Ord t, Ord k) => t -> TimedMap t k a -> TimedMap t k aSource

Delete all items older than the specified timestamp.

tmLimitSize :: Ord k => Int -> TimedMap t k a -> TimedMap t k aSource

Delete at least as many oldest items as necessary to limit the map's size to the given value. If you have multiple keys with the same timestamp, this function can delete more keys than necessary.