Struct index_pool::IndexPool
[−]
[src]
pub struct IndexPool { /* fields omitted */ }
A pool which manages allocation of unique indices. Acts like a psuedo-memory allocator.
Methods
impl IndexPool
[src]
fn new() -> Self
[src]
Constructs an empty IndexPool. Indices will start at 0
.
fn with_initial_index(index: usize) -> Self
[src]
Constructs an empty IndexPool. index
will be the first
index returned from new_id
. You can logically think of
this as either specifying a base index for the pool, or
pre-allocating the [0..index)
range. This datastructure
does not care which is your usecase, and neither has any
kind of performance penalty, except that in_use()
will
include the [0..index)
range.
fn new_id(&mut self) -> usize
[src]
Allocates a new index for use. This is guaranteed to not be any index
which has previously been returned from new_id
but has not yet been
passed to return_id
.
fn return_id(&mut self, id: usize) -> Result<(), AlreadyReturned>
[src]
Gives an Id back to the pool so that it may be handed out again. Returns Err if the Id was not in use at the time. Whether ignoring such an error is okay is up to your own usecase.
fn maximum(&self) -> usize
[src]
Returns an upper bound on the number of IDs which have been
allocated, specifically the highest numbered ID in use + 1
.
Useful if you're going to e.g. create a Vec which has room
for all of your IDs.
fn in_use(&self) -> usize
[src]
Returns the number of currently in-use indices
fn all_indices(&self) -> IndexIter
[src]
Returns an iterator over all indices which are in use