IPAL8739. Replace stack with set: assure increasing order or released IDs and clearing of ID pool when possible

This commit is contained in:
eap 2005-05-11 12:34:33 +00:00
parent 5e37ea4dc8
commit f5fcc431a4
2 changed files with 17 additions and 5 deletions

View File

@ -44,8 +44,9 @@ int SMDS_MeshIDFactory::GetFreeID()
if (myPoolOfID.empty()) return ++myMaxID; if (myPoolOfID.empty()) return ++myMaxID;
else else
{ {
int ID = myPoolOfID.top(); set<int>::iterator i = myPoolOfID.begin();
myPoolOfID.pop(); int ID = *i;//myPoolOfID.top();
myPoolOfID.erase( i );//myPoolOfID.pop();
return ID; return ID;
} }
} }
@ -56,5 +57,16 @@ int SMDS_MeshIDFactory::GetFreeID()
//======================================================================= //=======================================================================
void SMDS_MeshIDFactory::ReleaseID(const int ID) void SMDS_MeshIDFactory::ReleaseID(const int ID)
{ {
if (ID > 0 && ID < myMaxID) myPoolOfID.push(ID); if (ID > 0 && ID < myMaxID) myPoolOfID./*push*/insert(ID);
if (ID > 0 && ID == myMaxID ) {
set<int>::iterator i = --myPoolOfID.end();
while ( i != myPoolOfID.begin() )
if ( --myMaxID != *(--i) )
break;
if ( myMaxID == *i )
--myMaxID; // begin of myPoolOfID reached
else
++i;
myPoolOfID.erase( i, myPoolOfID.end() );
}
} }

View File

@ -28,7 +28,7 @@
#define _SMDS_MeshIDFactory_HeaderFile #define _SMDS_MeshIDFactory_HeaderFile
#include "SMDS_MeshObject.hxx" #include "SMDS_MeshObject.hxx"
#include <stack> #include <set>
class SMDS_MeshIDFactory:public SMDS_MeshObject class SMDS_MeshIDFactory:public SMDS_MeshObject
@ -40,7 +40,7 @@ class SMDS_MeshIDFactory:public SMDS_MeshObject
protected: protected:
SMDS_MeshIDFactory(); SMDS_MeshIDFactory();
int myMaxID; int myMaxID;
std::stack<int> myPoolOfID; std::set<int> myPoolOfID;
}; };
#endif #endif