From f5fcc431a49ff3152fdb4b37b17acfa08c8b1639 Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 11 May 2005 12:34:33 +0000 Subject: [PATCH] IPAL8739. Replace stack with set: assure increasing order or released IDs and clearing of ID pool when possible --- src/SMDS/SMDS_MeshIDFactory.cxx | 18 +++++++++++++++--- src/SMDS/SMDS_MeshIDFactory.hxx | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/SMDS/SMDS_MeshIDFactory.cxx b/src/SMDS/SMDS_MeshIDFactory.cxx index 96314592d..74ac917dd 100644 --- a/src/SMDS/SMDS_MeshIDFactory.cxx +++ b/src/SMDS/SMDS_MeshIDFactory.cxx @@ -44,8 +44,9 @@ int SMDS_MeshIDFactory::GetFreeID() if (myPoolOfID.empty()) return ++myMaxID; else { - int ID = myPoolOfID.top(); - myPoolOfID.pop(); + set::iterator i = myPoolOfID.begin(); + int ID = *i;//myPoolOfID.top(); + myPoolOfID.erase( i );//myPoolOfID.pop(); return ID; } } @@ -56,5 +57,16 @@ int SMDS_MeshIDFactory::GetFreeID() //======================================================================= 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::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() ); + } } diff --git a/src/SMDS/SMDS_MeshIDFactory.hxx b/src/SMDS/SMDS_MeshIDFactory.hxx index 62b2d4c00..8a6425ac2 100644 --- a/src/SMDS/SMDS_MeshIDFactory.hxx +++ b/src/SMDS/SMDS_MeshIDFactory.hxx @@ -28,7 +28,7 @@ #define _SMDS_MeshIDFactory_HeaderFile #include "SMDS_MeshObject.hxx" -#include +#include class SMDS_MeshIDFactory:public SMDS_MeshObject @@ -40,7 +40,7 @@ class SMDS_MeshIDFactory:public SMDS_MeshObject protected: SMDS_MeshIDFactory(); int myMaxID; - std::stack myPoolOfID; + std::set myPoolOfID; }; #endif -- 2.39.2