#hash-map #hash-set #collection #delay-queue #delay

delay_map

HashMap collections whose entries expire after a given time

6 releases (3 breaking)

0.4.0 Jul 11, 2024
0.3.0 Mar 7, 2023
0.2.0 Feb 6, 2023
0.1.2 Oct 27, 2022
0.1.0 Jan 31, 2022

#217 in Data structures

Download history 8220/week @ 2024-08-24 8326/week @ 2024-08-31 9652/week @ 2024-09-07 11213/week @ 2024-09-14 11602/week @ 2024-09-21 8422/week @ 2024-09-28 10787/week @ 2024-10-05 12717/week @ 2024-10-12 15276/week @ 2024-10-19 13903/week @ 2024-10-26 9926/week @ 2024-11-02 8860/week @ 2024-11-09 11105/week @ 2024-11-16 12478/week @ 2024-11-23 12048/week @ 2024-11-30 10951/week @ 2024-12-07

47,803 downloads per month
Used in 5 crates (2 directly)

Apache-2.0

21KB
331 lines

delay_map

Build Status Doc Status Crates Status

Documentation at docs.rs

Overview

This crate contains two data structures, HashSetDelay and HashMapDelay. These behave like the standard library HashSet and HashMaps with the added feature that entries inserted into the mappings expire after a fixed period of time.

Usage

Creating a map

    use delay_map::HashMapDelay;
    use futures::prelude::*;

    // Set a default timeout for entries
    let mut delay_map = HashMapDelay::new(std::time::Duration::from_secs(1));


    tokio_test::block_on(async {

    delay_map.insert(1, "entry_1");
    delay_map.insert(2, "entry_2");
    
    if let Some(Ok((key, value))) = delay_map.next().await {
        println!("Entry 1: {}, {}", key, value);  
    }

    if let Some(Ok((key, value))) = delay_map.next().await {
        println!("Entry 2: {}, {}", key,value);  
    }
    });

Dependencies

~3–8.5MB
~70K SLoC