UniqueIdAllocator
from panda3d.core import UniqueIdAllocator
- class UniqueIdAllocator
Bases:
DTOOL_SUPER_BASE
Manage a set of ID values from min to max inclusive. The ID numbers that are freed will be allocated (reused) in the same order. I.e. the oldest ID numbers will be allocated.
This implementation will use 4 bytes per id number, plus a few bytes of management data. e.g. 10,000 ID numbers will use 40KB.
Also be advised that ID -1 and -2 are used internally by the allocator. If allocate returns IndexEnd (-1) then the allocator is out of free ID numbers.
There are other implementations that can better leverage runs of used or unused IDs or use bit arrays for the IDs. But, it takes extra work to track the age of freed IDs, which is required for what we wanted. If you would like to kick around other implementation ideas, please contact Schuyler.
Inheritance diagram
- __init__(*args, **kwargs)
- allocate()
C++ Interface: allocate(const UniqueIdAllocator self)
- /**
Returns an id between _min and _max (that were passed to the constructor).
IndexEnd is returned if no ids are available.
*/
- fractionUsed()
C++ Interface: fraction_used(UniqueIdAllocator self)
- /**
return the decimal fraction of the pool that is used. The range is 0 to
1.0 (e.g. 75% would be 0.75).
*/
- fraction_used()
C++ Interface: fraction_used(UniqueIdAllocator self)
- /**
return the decimal fraction of the pool that is used. The range is 0 to
1.0 (e.g. 75% would be 0.75).
*/
- free()
C++ Interface: free(const UniqueIdAllocator self, int index)
- /**
Free an allocated index (index must be between _min and _max that were
passed to the constructor).
Since 1.11.0, returns true if the index has been freed successfully
or false if the index has not been allocated yet, instead of
triggering an assertion.
*/
- initialReserveId()
C++ Interface: initial_reserve_id(const UniqueIdAllocator self, int id)
- /**
This may be called to mark a particular id as having already been allocated
(for instance, by a prior pass). The specified id is removed from the
available pool.
Because of the limitations of this algorithm, this is most efficient when
it is called before the first call to allocate(), and when all the calls to
initial_reserve_id() are made in descending order by id. However, this is
a performance warning only; if performance is not an issue, any id may be
reserved at any time.
*/
- initial_reserve_id()
C++ Interface: initial_reserve_id(const UniqueIdAllocator self, int id)
- /**
This may be called to mark a particular id as having already been allocated
(for instance, by a prior pass). The specified id is removed from the
available pool.
Because of the limitations of this algorithm, this is most efficient when
it is called before the first call to allocate(), and when all the calls to
initial_reserve_id() are made in descending order by id. However, this is
a performance warning only; if performance is not an issue, any id may be
reserved at any time.
*/
- isAllocated()
C++ Interface: is_allocated(const UniqueIdAllocator self, int index)
- /**
Checks the allocated state of an index. Returns true for
indices that are currently allocated and in use.
*/
- is_allocated()
C++ Interface: is_allocated(const UniqueIdAllocator self, int index)
- /**
Checks the allocated state of an index. Returns true for
indices that are currently allocated and in use.
*/