uniqueIdAllocator

This commit is contained in:
Dave Schuyler 2003-03-14 20:07:54 +00:00
parent 6bfe3bcd42
commit bcb2f71f4b
3 changed files with 22 additions and 2 deletions

View File

@ -46,6 +46,7 @@
timedCycle.I timedCycle.h typedWritable.I \
typedWritable.h typedWritableReferenceCount.I \
typedWritableReferenceCount.h updateSeq.I updateSeq.h \
uniqueIdAllocator.h \
vector_double.h vector_float.h vector_typedWritable.h \
vector_ushort.h vector_writable.h \
writableConfigurable.h \
@ -75,6 +76,7 @@
pta_int.cxx pta_ushort.cxx \
string_utils.cxx timedCycle.cxx typedWritable.cxx \
typedWritableReferenceCount.cxx updateSeq.cxx \
uniqueIdAllocator.cxx \
vector_double.cxx vector_float.cxx \
vector_typedWritable.cxx \
vector_ushort.cxx vector_writable.cxx \
@ -116,6 +118,7 @@
string_utils.h timedCycle.I timedCycle.h typedWritable.I \
typedWritable.h typedWritableReferenceCount.I \
typedWritableReferenceCount.h updateSeq.I updateSeq.h \
uniqueIdAllocator.h \
vector_double.h vector_float.h vector_typedWritable.h \
vector_ushort.h vector_writable.h \
writableConfigurable.h writableParam.I \
@ -153,6 +156,14 @@
#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
#define TARGET test_glob

View File

@ -11,6 +11,7 @@
#include "typedWritable.cxx"
#include "typedWritableReferenceCount.cxx"
#include "updateSeq.cxx"
#include "uniqueIdAllocator.cxx"
#include "vector_double.cxx"
#include "vector_float.cxx"
#include "vector_typedWritable.cxx"

View File

@ -31,7 +31,7 @@ UniqueIdAllocator::
UniqueIdAllocator(U32 min, U32 max)
: _min(min), _max(max) {
//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.
_table=new U32[_size];
assert(_table); // This should be redundant if new throws an exception.
@ -98,11 +98,19 @@ void UniqueIdAllocator::
free(U32 index) {
//cout<<"UniqueIdAllocator::free(index)"<<endl;
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;
assert(_table[index]==-2); // Attempt to free non-allocated id.
_table[index]=-1;
_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;
++_free;
}