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]
pub fn new() -> Self
[src]
Constructs an empty IndexPool. Indices will start at 0
.
pub 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.
pub 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
.
pub fn request_id(&mut self, id: usize) -> Result<(), AlreadyInUse>
[src]
Attempts to allocate a specific index
pub 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.
pub 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.
pub fn in_use(&self) -> usize
[src]
Returns the number of currently in-use indices
pub fn is_free(&self, id: usize) -> bool
[src]
Checks if a specific index is currently free
ⓘImportant traits for IndexIter<'a>pub fn all_indices(&self) -> IndexIter
[src]
Returns an iterator over all indices which are in use
ⓘImportant traits for IndexAfterIter<'a>pub fn all_indices_after(&self, after: usize) -> IndexAfterIter
[src]
pub fn clear(&mut self)
[src]
Trait Implementations
impl Debug for IndexPool
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more