transient_map

Crates.io Docs.rs

TransientMap acts as a wrapper for std::collections::HashMap which allows for the eviction of unused elements. In addition to the standard hashmap API, it provides the following extra functions:

These additional functions make TransientMap an ideal choice for applications like caching, where it is desirable to efficiently discard data that has not been used.

The following is a brief example of how to use TransientMap:

```rust let mut map = TransientMap::new(); map.insertunused(1, "a"); map.insertunused(2, "b"); asserteq!(Some("b"), map.remove(&2)); map.insert(3, "c"); map.insert(4, "d"); asserteq!(vec!((1, "a")), map.drain_unused().collect::>());

let mut res = map.drainunused().collect::>(); res.sortby(|a, b| a.0.cmp(&b.0));

asserteq!(vec!((3, "c"), (4, "d")), res); asserteq!(0, map.len()); ```