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

delay_map

HashMap collections whose entries expire after a given time

5 unstable releases

0.3.0 Mar 7, 2023
0.2.0 Feb 6, 2023
0.1.2 Oct 27, 2022
0.1.1 Mar 20, 2022
0.1.0 Jan 31, 2022

#1267 in Data structures

Download history 4296/week @ 2023-12-15 3002/week @ 2023-12-22 3319/week @ 2023-12-29 5387/week @ 2024-01-05 5922/week @ 2024-01-12 6590/week @ 2024-01-19 6793/week @ 2024-01-26 6860/week @ 2024-02-02 5383/week @ 2024-02-09 7047/week @ 2024-02-16 7538/week @ 2024-02-23 7158/week @ 2024-03-01 8156/week @ 2024-03-08 7437/week @ 2024-03-15 6530/week @ 2024-03-22 4864/week @ 2024-03-29

28,248 downloads per month
Used in 5 crates (2 directly)

Apache-2.0

19KB
299 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–4.5MB
~69K SLoC