| Crates.io | expiration_list |
| lib.rs | expiration_list |
| version | 2.0.0 |
| created_at | 2025-12-04 07:06:01.479223+00 |
| updated_at | 2025-12-05 03:43:09.101264+00 |
| description | A datastructure for items that expire. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1966061 |
| size | 29,696 |
A datastructure for items that expire.
ExpirationList is more performant than a HashMap for items that are likely to be removed over time and require a stable ID which can be a usize. It does not automatically remove items or track expiry. It should not be used when the expiration is fixed, in this case there are other more efficient datastructures such as priority queues.
Add and remove:
use expiration_list::ExpirationList;
let mut list = ExpirationList::new();
let value: i32 = 1234;
let id = list.add(value);
assert_eq!(list.get(id), Some(&value));
let removed_value: i32 = list.remove(id).ok_or(0)?;
assert_eq!(removed_value, value);
assert_eq!(list.get(id), None);
Adding and removing many items:
use expiration_list::ExpirationList;
let mut list = ExpirationList::new();
for idx in 0..10_000 {
list.add(idx);
}
assert!(list.capacity() >= 10_000);
for idx in 0..(10_000 - 10) {
list.remove(idx);
}
assert_eq!(list.len(), 10);
// The capacity of the inner structures are reduced
assert_eq!(list.capacity(), 40);
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.