mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
putil: add is_allocated convenience method to UniqueIdAllocator
Closes #580
This commit is contained in:
parent
138e7f935f
commit
fb0807d769
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user