6 releases
new 0.2.2 | Nov 10, 2024 |
---|---|
0.2.1 | Oct 2, 2024 |
0.2.0 | Sep 20, 2024 |
0.1.2 | Jan 23, 2024 |
0.1.1 | Aug 30, 2023 |
#740 in Data structures
106 downloads per month
Used in 3 crates
13KB
275 lines
idbag
A bag of integers that can be allocated and then returned to the bag.
lib.rs
:
An id bag is conceptually a bag that initially contains (all) intger values of the type of the bag. An application can request to allocate an id from the bag, which behaves like the identifier has been taken out of the bag. Once the id is dropped its integer will automatically be returned to the bag and be available for allocation again.
Allocated identifier objects are hashable and derefernces to its internal integer value.
Introductionary example
use idbag::IdBagU32;
// Create a new id bag.
let idbag = IdBagU32::new();
// Allocate an id; first id will have a value of 1.
let id = idbag.alloc();
assert_eq!(id.val(), 1);
// The id's drop handler returns 1 to the idbag
drop(id);
// Allocate another id; next id will have a value of 2.
let id = idbag.alloc();
assert_eq!(id.val(), 2);
// The id's drop handler returns 2 to the idbag
drop(id);
Assigned integer semantics
The assigned integer increases by one each time a new id has been allocated and wraps around at its maximum value.
Dependencies
~1.1–5.5MB
~23K SLoC