From bcb2f71f4b3ca718e71142ed7dae0ffe73acfb4e Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Fri, 14 Mar 2003 20:07:54 +0000 Subject: [PATCH] uniqueIdAllocator --- panda/src/putil/Sources.pp | 11 +++++++++++ panda/src/putil/putil_composite2.cxx | 1 + panda/src/putil/uniqueIdAllocator.cxx | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/panda/src/putil/Sources.pp b/panda/src/putil/Sources.pp index c1d4bbf826..9a1b5cd868 100644 --- a/panda/src/putil/Sources.pp +++ b/panda/src/putil/Sources.pp @@ -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 diff --git a/panda/src/putil/putil_composite2.cxx b/panda/src/putil/putil_composite2.cxx index 881953fb73..6a8b3c6c38 100644 --- a/panda/src/putil/putil_composite2.cxx +++ b/panda/src/putil/putil_composite2.cxx @@ -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" diff --git a/panda/src/putil/uniqueIdAllocator.cxx b/panda/src/putil/uniqueIdAllocator.cxx index dfd72606a9..cfcd83e7b8 100644 --- a/panda/src/putil/uniqueIdAllocator.cxx +++ b/panda/src/putil/uniqueIdAllocator.cxx @@ -31,7 +31,7 @@ UniqueIdAllocator:: UniqueIdAllocator(U32 min, U32 max) : _min(min), _max(max) { //cout<<"UniqueIdAllocator::UniqueIdAllocator("< 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)"<=_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; }