putil: add is_allocated convenience method to UniqueIdAllocator

Closes #580
This commit is contained in:
Daniel 2019-03-12 01:08:27 +02:00 committed by rdb
parent 138e7f935f
commit fb0807d769
2 changed files with 16 additions and 0 deletions

View File

@ -173,6 +173,20 @@ initial_reserve_id(uint32_t id) {
--_free;
}
/**
* Checks the allocated state of an index. Returns true for
* indices that are currently allocated and in use.
*/
bool UniqueIdAllocator::
is_allocated(uint32_t id) {
if (id < _min || id > _max) {
// This id is out of range, not allocated.
return false;
}
uint32_t index = id - _min; // Convert to _table index.
return _table[index] == IndexAllocated;
}
/**
* Free an allocated index (index must be between _min and _max that were

View File

@ -43,6 +43,8 @@ PUBLISHED:
uint32_t allocate();
void initial_reserve_id(uint32_t id);
bool is_allocated(uint32_t index);
void free(uint32_t index);
PN_stdfloat fraction_used() const;