Salome HOME
IPAL8739. Replace stack with set: assure increasing order or released IDs and clearin...
authoreap <eap@opencascade.com>
Wed, 11 May 2005 12:34:33 +0000 (12:34 +0000)
committereap <eap@opencascade.com>
Wed, 11 May 2005 12:34:33 +0000 (12:34 +0000)
src/SMDS/SMDS_MeshIDFactory.cxx
src/SMDS/SMDS_MeshIDFactory.hxx

index 96314592de10318b74ff108f3e67fdae9a8ca67a..74ac917ddbfa02cb7dfd1965ca5471e3ec369fb6 100644 (file)
@@ -44,8 +44,9 @@ int SMDS_MeshIDFactory::GetFreeID()
        if (myPoolOfID.empty()) return ++myMaxID;
        else
        {
-               int ID = myPoolOfID.top();
-               myPoolOfID.pop();
+                set<int>::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<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() );
+  }
 }
index 62b2d4c008235812d41c066a103e7fadeb5bb4fc..8a6425ac2512b4b8023e2df34afb7d2286a78b88 100644 (file)
@@ -28,7 +28,7 @@
 #define _SMDS_MeshIDFactory_HeaderFile
 
 #include "SMDS_MeshObject.hxx"
-#include <stack>
+#include <set>
 
 
 class SMDS_MeshIDFactory:public SMDS_MeshObject
@@ -40,7 +40,7 @@ class SMDS_MeshIDFactory:public SMDS_MeshObject
   protected:
        SMDS_MeshIDFactory();
        int myMaxID;
-       std::stack<int> myPoolOfID;
+       std::set<int> myPoolOfID;
 };
 
 #endif