mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
uniqueIdAllocator
This commit is contained in:
parent
6bfe3bcd42
commit
bcb2f71f4b
@ -46,6 +46,7 @@
|
|||||||
timedCycle.I timedCycle.h typedWritable.I \
|
timedCycle.I timedCycle.h typedWritable.I \
|
||||||
typedWritable.h typedWritableReferenceCount.I \
|
typedWritable.h typedWritableReferenceCount.I \
|
||||||
typedWritableReferenceCount.h updateSeq.I updateSeq.h \
|
typedWritableReferenceCount.h updateSeq.I updateSeq.h \
|
||||||
|
uniqueIdAllocator.h \
|
||||||
vector_double.h vector_float.h vector_typedWritable.h \
|
vector_double.h vector_float.h vector_typedWritable.h \
|
||||||
vector_ushort.h vector_writable.h \
|
vector_ushort.h vector_writable.h \
|
||||||
writableConfigurable.h \
|
writableConfigurable.h \
|
||||||
@ -75,6 +76,7 @@
|
|||||||
pta_int.cxx pta_ushort.cxx \
|
pta_int.cxx pta_ushort.cxx \
|
||||||
string_utils.cxx timedCycle.cxx typedWritable.cxx \
|
string_utils.cxx timedCycle.cxx typedWritable.cxx \
|
||||||
typedWritableReferenceCount.cxx updateSeq.cxx \
|
typedWritableReferenceCount.cxx updateSeq.cxx \
|
||||||
|
uniqueIdAllocator.cxx \
|
||||||
vector_double.cxx vector_float.cxx \
|
vector_double.cxx vector_float.cxx \
|
||||||
vector_typedWritable.cxx \
|
vector_typedWritable.cxx \
|
||||||
vector_ushort.cxx vector_writable.cxx \
|
vector_ushort.cxx vector_writable.cxx \
|
||||||
@ -116,6 +118,7 @@
|
|||||||
string_utils.h timedCycle.I timedCycle.h typedWritable.I \
|
string_utils.h timedCycle.I timedCycle.h typedWritable.I \
|
||||||
typedWritable.h typedWritableReferenceCount.I \
|
typedWritable.h typedWritableReferenceCount.I \
|
||||||
typedWritableReferenceCount.h updateSeq.I updateSeq.h \
|
typedWritableReferenceCount.h updateSeq.I updateSeq.h \
|
||||||
|
uniqueIdAllocator.h \
|
||||||
vector_double.h vector_float.h vector_typedWritable.h \
|
vector_double.h vector_float.h vector_typedWritable.h \
|
||||||
vector_ushort.h vector_writable.h \
|
vector_ushort.h vector_writable.h \
|
||||||
writableConfigurable.h writableParam.I \
|
writableConfigurable.h writableParam.I \
|
||||||
@ -153,6 +156,14 @@
|
|||||||
|
|
||||||
#end test_bin_target
|
#end test_bin_target
|
||||||
|
|
||||||
|
#begin test_bin_target
|
||||||
|
#define TARGET test_uniqueIdAllocator
|
||||||
|
|
||||||
|
#define SOURCES \
|
||||||
|
test_uniqueIdAllocator.cxx
|
||||||
|
|
||||||
|
#end test_bin_target
|
||||||
|
|
||||||
#begin test_bin_target
|
#begin test_bin_target
|
||||||
#define TARGET test_glob
|
#define TARGET test_glob
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "typedWritable.cxx"
|
#include "typedWritable.cxx"
|
||||||
#include "typedWritableReferenceCount.cxx"
|
#include "typedWritableReferenceCount.cxx"
|
||||||
#include "updateSeq.cxx"
|
#include "updateSeq.cxx"
|
||||||
|
#include "uniqueIdAllocator.cxx"
|
||||||
#include "vector_double.cxx"
|
#include "vector_double.cxx"
|
||||||
#include "vector_float.cxx"
|
#include "vector_float.cxx"
|
||||||
#include "vector_typedWritable.cxx"
|
#include "vector_typedWritable.cxx"
|
||||||
|
@ -31,7 +31,7 @@ UniqueIdAllocator::
|
|||||||
UniqueIdAllocator(U32 min, U32 max)
|
UniqueIdAllocator(U32 min, U32 max)
|
||||||
: _min(min), _max(max) {
|
: _min(min), _max(max) {
|
||||||
//cout<<"UniqueIdAllocator::UniqueIdAllocator("<<min<<", "<<max<<")"<<endl;
|
//cout<<"UniqueIdAllocator::UniqueIdAllocator("<<min<<", "<<max<<")"<<endl;
|
||||||
_size=_max-_min;
|
_size=_max-_min+1; // +1 because min and max are inclusive.
|
||||||
assert(_size); // size must be > 0.
|
assert(_size); // size must be > 0.
|
||||||
_table=new U32[_size];
|
_table=new U32[_size];
|
||||||
assert(_table); // This should be redundant if new throws an exception.
|
assert(_table); // This should be redundant if new throws an exception.
|
||||||
@ -98,11 +98,19 @@ void UniqueIdAllocator::
|
|||||||
free(U32 index) {
|
free(U32 index) {
|
||||||
//cout<<"UniqueIdAllocator::free(index)"<<endl;
|
//cout<<"UniqueIdAllocator::free(index)"<<endl;
|
||||||
assert(index>=_min); // Attempt to free out-of-range id.
|
assert(index>=_min); // Attempt to free out-of-range id.
|
||||||
assert(index<_max); // Attempt to free out-of-range id.
|
assert(index<=_max); // Attempt to free out-of-range id.
|
||||||
index=index-_min;
|
index=index-_min;
|
||||||
assert(_table[index]==-2); // Attempt to free non-allocated id.
|
assert(_table[index]==-2); // Attempt to free non-allocated id.
|
||||||
_table[index]=-1;
|
_table[index]=-1;
|
||||||
_table[_last_free]=index;
|
_table[_last_free]=index;
|
||||||
|
#if 0 //[
|
||||||
|
// This is only necessary if the free pool is allowed to go empty.
|
||||||
|
// Since we don't allow that, it is an optimization to comment
|
||||||
|
// this out.
|
||||||
|
if (_next_free==-1) {
|
||||||
|
_next_free=index;
|
||||||
|
}
|
||||||
|
#endif //]
|
||||||
_last_free=index;
|
_last_free=index;
|
||||||
++_free;
|
++_free;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user