#map #expiry #expire #hash-map #ttl

expiremap

A simple Key-Value map where each value has a custom expiry time

2 releases

0.1.0-beta.1 Jan 16, 2025
0.1.0-beta.0 Oct 27, 2024

#655 in Data structures

Download history 107/week @ 2024-10-26 20/week @ 2024-11-02 1/week @ 2024-11-09 1/week @ 2024-11-16 15/week @ 2024-12-07 9/week @ 2024-12-14 100/week @ 2025-01-11 24/week @ 2025-01-18 7/week @ 2025-02-01

131 downloads per month

MIT/Apache

9KB
150 lines

ExpireMap

NOTE: This is a very early and lean beta version

A simple Key-Value map where each item has an associated expiry time. Calling .expire(<time>) on the map removes all items which are past their expiry (<=

The expiry time does not have to be based on actual time, anything implementing the Ord trait can be used, making this map useful for usage with logical timestamps.

Example

use expiremap::ExpireMap;

let mut map = ExpireMap::new();

// key, value, expiry time
map.insert("foo", "bar", 1);
map.insert("baz", "bar", 3);
// removes all items with expiry 
map.expire(2)
assert!(map.get("foo").is_none());
assert!(map.get("baz").is_some());

Dependencies

~1MB
~14K SLoC