]> OCCT Git - occt.git/commitdiff
Foundation Classes - Move Map's algo part to external file #213
authordpasukhi <dpasukhi@opencascade.com>
Fri, 27 Dec 2024 10:36:43 +0000 (10:36 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Fri, 27 Dec 2024 13:07:05 +0000 (13:07 +0000)
Updated multiple classes to utilize the new NCollection_MapAlgo
  for union, intersection, and other set operations,
    improving code structure and maintainability.
Deprecated older methods in NCollection_Map in favor of the new algorithmic approaches.

src/BRepMesh/BRepMesh_FaceChecker.cxx
src/BRepMesh/BRepMesh_ModelHealer.cxx
src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx
src/BRepOffset/BRepOffset_MakeOffset_1.cxx
src/NCollection/FILES
src/NCollection/NCollection_Map.hxx
src/NCollection/NCollection_MapAlgo.hxx [new file with mode: 0644]
src/QABugs/QABugs_19.cxx
src/QANCollection/QANCollection_Test.cxx
src/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx
src/XCAFDoc/XCAFDoc_Editor.cxx

index b78238d692857d6fc3910d8cd37f3e7fda43eddc..6a13327f44ba83984da7a955d9214c5c4d9d9b35 100644 (file)
@@ -309,7 +309,7 @@ void BRepMesh_FaceChecker::collectResult()
     const Handle(IMeshData::MapOfIEdgePtr)& aEdges = myWiresIntersectingEdges->Value(aWireIt);
     if (!aEdges.IsNull())
     {
-      myIntersectingEdges->Unite(*aEdges);
+      NCollection_MapAlgo::Unite(*myIntersectingEdges, *aEdges);
     }
   }
 }
index 4c2eed209ac8e31e36cdf9bb5faadfd98c585e77..575c7493f0d1b146e5ab2d73f0138bc8dc5e1dda 100644 (file)
@@ -235,7 +235,7 @@ Standard_Boolean BRepMesh_ModelHealer::popEdgesToUpdate(
     Handle(IMeshData::MapOfIEdgePtr)& aIntersections = aFaceIt.ChangeValue();
     if (!aIntersections.IsNull())
     {
-      theEdgesToUpdate.Unite(*aIntersections);
+      NCollection_MapAlgo::Unite(theEdgesToUpdate, *aIntersections);
       aIntersections.Nullify();
     }
   }
index 0f78d5e924f3361656f10584b1e2fed1a7d6af6e..ea8a2b672a4a45fda5e4d96305df68a05ceb0525 100644 (file)
@@ -361,8 +361,8 @@ Handle(IMeshData::ListOfPnt2d) BRepMesh_NURBSRangeSplitter::GenerateSurfaceNodes
       aFixedParams[0], aFixedParams[1]).GetControlParametersToRemove(theParameters),
   };
 
-  aParamsToRemove[0]->Subtract(*aFixedParams[0]);
-  aParamsToRemove[1]->Subtract(*aFixedParams[1]);
+  NCollection_MapAlgo::Subtract(*aParamsToRemove[0], *aFixedParams[0]);
+  NCollection_MapAlgo::Subtract(*aParamsToRemove[1], *aFixedParams[1]);
 
   // insert nodes of the regular grid
   Handle(IMeshData::ListOfPnt2d) aNodes = new IMeshData::ListOfPnt2d(
index 216f095f7370a962eb4a22263aa1f545e575ed77..7058e241d32a4f420030f255d1dd2ecef3cf8b85 100644 (file)
@@ -3362,7 +3362,7 @@ Standard_Boolean BRepOffset_BuildOffsetFaces::CheckInvertedBlock (const TopoDS_S
       GetVerticesOnEdges (aCB1, myInvertedEdges, *pMVInverted1, *pMVAll1);
     }
     //
-    if (pMVInverted->HasIntersection (*pMVAll1))
+    if (NCollection_MapAlgo::HasIntersection(*pMVInverted, *pMVAll1))
     {
       return Standard_False;
     }
@@ -5886,8 +5886,8 @@ void BRepOffset_BuildOffsetFaces::IntersectFaces (TopTools_MapOfShape& theVertsT
           mapShapes(*aLFImi, TopAbs_EDGE, aMEVIm);
           mapShapes(*aLFImi, TopAbs_VERTEX, aMEVIm);
 
-          Standard_Boolean isIContainsE = aMEVIm.HasIntersection(anInsideEdges);
-          Standard_Boolean isIContainsV = aMEVIm.HasIntersection(anInsideVertices);
+          Standard_Boolean isIContainsE = NCollection_MapAlgo::HasIntersection(aMEVIm, anInsideEdges);
+          Standard_Boolean isIContainsV = NCollection_MapAlgo::HasIntersection(aMEVIm, anInsideVertices);
 
           for (j = i + 1; j <= aNb; ++j)
           {
@@ -5914,8 +5914,8 @@ void BRepOffset_BuildOffsetFaces::IntersectFaces (TopTools_MapOfShape& theVertsT
             mapShapes(*aLFImj, TopAbs_VERTEX, aMEVIm);
             // check images of both faces contain anInsideEdges and anInsideVertices
             // not process if false and true 
-            Standard_Boolean isJContainsE = aMEVIm.HasIntersection(anInsideEdges);
-            Standard_Boolean isJContainsV = aMEVIm.HasIntersection(anInsideVertices);
+            Standard_Boolean isJContainsE = NCollection_MapAlgo::HasIntersection(aMEVIm, anInsideEdges);
+            Standard_Boolean isJContainsV = NCollection_MapAlgo::HasIntersection(aMEVIm, anInsideVertices);
 
             // Check if one face is connected to inside edge then
             // the other must be also connected
index 9ddad29b4b796193acdfd472bd9b49e1a9cdcf75..0092517dea0952db01d14c1280692d12269c076d 100755 (executable)
@@ -46,6 +46,7 @@ NCollection_List.hxx
 NCollection_ListNode.hxx
 NCollection_LocalArray.hxx
 NCollection_Map.hxx
+NCollection_MapAlgo.hxx
 NCollection_Mat3.hxx
 NCollection_Mat4.hxx
 NCollection_OccAllocator.hxx
index ca7f0135b33cdc89eefd1d43b01a1a035abd0e52..edc9772e656a1bf3ef85639bb3735b4eeefdd01c 100644 (file)
 #ifndef NCollection_Map_HeaderFile
 #define NCollection_Map_HeaderFile
 
+#include <NCollection_MapAlgo.hxx>
 #include <NCollection_DataMap.hxx>
-#include <NCollection_TListNode.hxx>
-#include <NCollection_StlIterator.hxx>
 #include <NCollection_DefaultHasher.hxx>
-
+#include <NCollection_StlIterator.hxx>
+#include <NCollection_TListNode.hxx>
 #include <Standard_NoSuchObject.hxx>
+
 #include <utility>
 
 /**
@@ -348,204 +349,80 @@ public:
   Standard_Integer Size(void) const
   { return Extent(); }
 
- public:
-  //!@name Boolean operations with maps as sets of keys
-  //!@{
+public:
 
-  //! @return true if two maps contains exactly the same keys
-  Standard_Boolean IsEqual (const NCollection_Map& theOther) const
+  //! Checks if two maps contain exactly the same keys.
+  //! This function compares the keys of this map and another map and returns true
+  //! if they contain exactly the same keys.
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  Standard_Boolean IsEqual(const NCollection_Map& theOther) const
   {
-    return Extent() == theOther.Extent()
-        && Contains (theOther);
+    return NCollection_MapAlgo::IsEqual<NCollection_Map>(*this, theOther);
   }
 
-  //! @return true if this map contains ALL keys of another map.
-  Standard_Boolean Contains (const NCollection_Map& theOther) const
+  //! Checks if this map contains all keys of another map.
+  //! This function checks if this map contains all keys of another map.
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  Standard_Boolean Contains(const NCollection_Map& theOther) const
   {
-    if (this == &theOther
-     || theOther.IsEmpty())
-    {
-      return Standard_True;
-    }
-    else if (Extent() < theOther.Extent())
-    {
-      return Standard_False;
-    }
-
-    for (Iterator anIter (theOther); anIter.More(); anIter.Next())
-    {
-      if (!Contains (anIter.Key()))
-      {
-        return Standard_False;
-      }
-    }
-
-    return Standard_True;
+    return NCollection_MapAlgo::Contains<NCollection_Map>(*this, theOther);
   }
 
   //! Sets this Map to be the result of union (aka addition, fuse, merge, boolean OR) operation between two given Maps
   //! The new Map contains the values that are contained either in the first map or in the second map or in both.
   //! All previous content of this Map is cleared.
   //! This map (result of the boolean operation) can also be passed as one of operands.
-  void Union (const NCollection_Map& theLeft,
-              const NCollection_Map& theRight)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  void Union(const NCollection_Map& theLeft, const NCollection_Map& theRight)
   {
-    if (&theLeft == &theRight)
-    {
-      Assign (theLeft);
-      return;
-    }
-
-    if (this != &theLeft
-     && this != &theRight)
-    {
-      Clear();
-    }
-
-    if (this != &theLeft)
-    {
-      for (Iterator anIter (theLeft); anIter.More(); anIter.Next())
-      {
-        Add (anIter.Key());
-      }
-    }
-    if (this != &theRight)
-    {
-      for (Iterator anIter (theRight); anIter.More(); anIter.Next())
-      {
-        Add (anIter.Key());
-      }
-    }
+    NCollection_MapAlgo::Union<NCollection_Map>(*this, theLeft, theRight);
   }
 
   //! Apply to this Map the boolean operation union (aka addition, fuse, merge, boolean OR) with another (given) Map.
   //! The result contains the values that were previously contained in this map or contained in the given (operand) map.
   //! This algorithm is similar to method Union().
   //! Returns True if contents of this map is changed.
-  Standard_Boolean Unite (const NCollection_Map& theOther)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  Standard_Boolean Unite(const NCollection_Map& theOther)
   {
-    if (this == &theOther)
-    {
-      return Standard_False;
-    }
-
-    const Standard_Integer anOldExtent = Extent();
-    Union (*this, theOther);
-    return anOldExtent != Extent();
+    return NCollection_MapAlgo::Unite<NCollection_Map>(*this, theOther);
   }
 
   //! Returns true if this and theMap have common elements.
-  Standard_Boolean HasIntersection (const NCollection_Map& theMap) const
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  Standard_Boolean HasIntersection(const NCollection_Map& theMap) const
   {
-    const NCollection_Map* aMap1 = this;
-    const NCollection_Map* aMap2 = &theMap;
-    if (theMap.Size() < Size())
-    {
-      aMap1 = &theMap;
-      aMap2 = this;
-    }
-
-    for (NCollection_Map::Iterator aIt(*aMap1); aIt.More(); aIt.Next())
-    {
-      if (aMap2->Contains(aIt.Value()))
-      {
-        return Standard_True;
-      }
-    }
-
-    return Standard_False;
+    return NCollection_MapAlgo::HasIntersection<NCollection_Map>(*this, theMap);
   }
 
   //! Sets this Map to be the result of intersection (aka multiplication, common, boolean AND) operation between two given Maps.
   //! The new Map contains only the values that are contained in both map operands.
   //! All previous content of this Map is cleared.
   //! This same map (result of the boolean operation) can also be used as one of operands.
-  void Intersection (const NCollection_Map& theLeft,
-                     const NCollection_Map& theRight)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  void Intersection(const NCollection_Map& theLeft, const NCollection_Map& theRight)
   {
-    if (&theLeft == &theRight)
-    {
-      Assign (theLeft);
-      return;
-    }
-
-    if (this == &theLeft)
-    {
-      NCollection_Map aCopy (1, this->myAllocator);
-      Exchange     (aCopy);
-      Intersection (aCopy, theRight);
-      return;
-    }
-    else if (this == &theRight)
-    {
-      NCollection_Map aCopy (1, this->myAllocator);
-      Exchange     (aCopy);
-      Intersection (theLeft, aCopy);
-      return;
-    }
-
-    Clear();
-    if (theLeft.Extent() < theRight.Extent())
-    {
-      for (Iterator anIter (theLeft); anIter.More(); anIter.Next())
-      {
-        if (theRight.Contains (anIter.Key()))
-        {
-          Add (anIter.Key());
-        }
-      }
-    }
-    else
-    {
-      for (Iterator anIter (theRight); anIter.More(); anIter.Next())
-      {
-        if (theLeft.Contains (anIter.Key()))
-        {
-          Add (anIter.Key());
-        }
-      }
-    }
+    NCollection_MapAlgo::Intersection<NCollection_Map>(*this, theLeft, theRight);
   }
 
   //! Apply to this Map the intersection operation (aka multiplication, common, boolean AND) with another (given) Map.
   //! The result contains only the values that are contained in both this and the given maps.
   //! This algorithm is similar to method Intersection().
   //! Returns True if contents of this map is changed.
-  Standard_Boolean Intersect (const NCollection_Map& theOther)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  Standard_Boolean Intersect(const NCollection_Map& theOther)
   {
-    if (this == &theOther
-     || IsEmpty())
-    {
-      return Standard_False;
-    }
-
-    const Standard_Integer anOldExtent = Extent();
-    Intersection (*this, theOther);
-    return anOldExtent != Extent();
+    return NCollection_MapAlgo::Intersect<NCollection_Map>(*this, theOther);
   }
 
   //! Sets this Map to be the result of subtraction (aka set-theoretic difference, relative complement,
   //! exclude, cut, boolean NOT) operation between two given Maps.
   //! The new Map contains only the values that are contained in the first map operands and not contained in the second one.
   //! All previous content of this Map is cleared.
-  void Subtraction (const NCollection_Map& theLeft,
-                    const NCollection_Map& theRight)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  void Subtraction(const NCollection_Map& theLeft, const NCollection_Map& theRight)
   {
-    if (this == &theLeft)
-    {
-      Subtract (theRight);
-      return;
-    }
-    else if (this == &theRight)
-    {
-      NCollection_Map aCopy (1, this->myAllocator);
-      Exchange    (aCopy);
-      Subtraction (theLeft, aCopy);
-      return;
-    }
-
-    Assign   (theLeft);
-    Subtract (theRight);
+    NCollection_MapAlgo::Subtraction<NCollection_Map>(*this, theLeft, theRight);
   }
 
   //! Apply to this Map the subtraction (aka set-theoretic difference, relative complement,
@@ -553,89 +430,29 @@ public:
   //! The result contains only the values that were previously contained in this map and not contained in this map.
   //! This algorithm is similar to method Subtract() with two operands.
   //! Returns True if contents of this map is changed.
-  Standard_Boolean Subtract (const NCollection_Map& theOther)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  Standard_Boolean Subtract(const NCollection_Map& theOther)
   {
-    if (this == &theOther)
-    {
-      if (IsEmpty())
-      {
-        return Standard_False;
-      }
-
-      Clear();
-      return Standard_True;
-    }
-
-    const Standard_Integer anOldExtent = Extent();
-    for (Iterator anIter (theOther); anIter.More(); anIter.Next())
-    {
-      Remove (anIter.Key());
-    }
-    return anOldExtent != Extent();
+    return NCollection_MapAlgo::Subtract<NCollection_Map>(*this, theOther);
   }
 
   //! Sets this Map to be the result of symmetric difference (aka exclusive disjunction, boolean XOR) operation between two given Maps.
   //! The new Map contains the values that are contained only in the first or the second operand maps but not in both.
   //! All previous content of this Map is cleared. This map (result of the boolean operation) can also be used as one of operands.
-  void Difference (const NCollection_Map& theLeft,
-                   const NCollection_Map& theRight)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  void Difference(const NCollection_Map& theLeft, const NCollection_Map& theRight)
   {
-    if (&theLeft == &theRight)
-    {
-      Clear();
-      return;
-    }
-    else if (this == &theLeft)
-    {
-      NCollection_Map aCopy (1, this->myAllocator);
-      Exchange   (aCopy);
-      Difference (aCopy, theRight);
-      return;
-    }
-    else if (this == &theRight)
-    {
-      NCollection_Map aCopy (1, this->myAllocator);
-      Exchange   (aCopy);
-      Difference (theLeft, aCopy);
-      return;
-    }
-
-    Clear();
-    for (Iterator anIter (theLeft); anIter.More(); anIter.Next())
-    {
-      if (!theRight.Contains (anIter.Key()))
-      {
-        Add (anIter.Key());
-      }
-    }
-    for (Iterator anIter (theRight); anIter.More(); anIter.Next())
-    {
-      if (!theLeft.Contains (anIter.Key()))
-      {
-        Add (anIter.Key());
-      }
-    }
+    NCollection_MapAlgo::Difference<NCollection_Map>(*this, theLeft, theRight);
   }
 
   //! Apply to this Map the symmetric difference (aka exclusive disjunction, boolean XOR) operation with another (given) Map.
   //! The result contains the values that are contained only in this or the operand map, but not in both.
   //! This algorithm is similar to method Difference().
   //! Returns True if contents of this map is changed.
-  Standard_Boolean Differ (const NCollection_Map& theOther)
+  Standard_DEPRECATED("This method will be removed right after 7.9. release. Use methods from NCollection_MapAlgo.hxx instead.")
+  Standard_Boolean Differ(const NCollection_Map& theOther)
   {
-    if (this == &theOther)
-    {
-      if (IsEmpty())
-      {
-        return Standard_False;
-      }
-      Clear();
-      return Standard_True;
-    }
-
-    const Standard_Integer anOldExtent = Extent();
-    Difference (*this, theOther);
-    return anOldExtent != Extent();
+    return NCollection_MapAlgo::Differ<NCollection_Map>(*this, theOther);
   }
 
 protected:
diff --git a/src/NCollection/NCollection_MapAlgo.hxx b/src/NCollection/NCollection_MapAlgo.hxx
new file mode 100644 (file)
index 0000000..330970b
--- /dev/null
@@ -0,0 +1,334 @@
+// Copyright (c) 2024 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef NCollection_MapAlgo_HeaderFile
+#define NCollection_MapAlgo_HeaderFile
+
+//! This namespace contains algorithms and utilities for managing NCollection_Map.
+//!
+//! The NCollection_MapAlgo namespace provides a set of template functions
+//! that facilitate the manipulation and management of NCollection_Map instances.
+//! These algorithms are designed to be efficient and easy to use, providing
+//! common operations such as union, intersection, subtraction, and symmetric difference
+//! on map collections.
+namespace NCollection_MapAlgo
+{
+  //! Sets this Map to be the result of union (aka addition, fuse, merge, boolean OR)
+  //! operation between two given Maps. The new Map contains the values that are
+  //! contained either in the first map or in the second map or in both.
+  //! All previous content of this Map is cleared. This map (result of the boolean
+  //! operation) can also be passed as one of operands.
+  template<class MapType>
+  void Union(MapType& theMap, const MapType& theLeftMap, const MapType& theRightMap)
+  {
+    if (&theLeftMap == &theRightMap)
+    {
+      theMap.Assign(theLeftMap);
+      return;
+    }
+
+    if (&theMap != &theLeftMap && &theMap != &theRightMap)
+    {
+      theMap.Clear();
+    }
+
+    if (&theMap != &theLeftMap)
+    {
+      for (typename MapType::Iterator anIter(theLeftMap); anIter.More(); anIter.Next())
+      {
+        theMap.Add(anIter.Key());
+      }
+    }
+    if (&theMap != &theRightMap)
+    {
+      for (typename MapType::Iterator anIter(theRightMap); anIter.More(); anIter.Next())
+      {
+        theMap.Add(anIter.Key());
+      }
+    }
+  }
+
+  //! Apply to this Map the boolean operation union (aka addition, fuse, merge, boolean OR)
+  //! with another (given) Map. The result contains the values that were previously
+  //! contained in this map or contained in the given (operand) map. This algorithm is
+  //! similar to method Union(). Returns True if contents of this map is changed.
+  template<class MapType>
+  bool Unite(MapType& theMap, const MapType& theOtherMap)
+  {
+    if (&theMap == &theOtherMap)
+    {
+      return false;
+    }
+
+    const int anOldExtent = theMap.Extent();
+    Union<MapType>(theMap, theMap, theOtherMap);
+    return anOldExtent != theMap.Extent();
+  }
+
+  //! Returns true if this and theMap have common elements.
+  template<class MapType>
+  bool HasIntersection(const MapType& theMap, const MapType& theOtherMap)
+  {
+    const MapType* aMap1 = &theMap;
+    const MapType* aMap2 = &theOtherMap;
+    if (theOtherMap.Size() < theMap.Size())
+    {
+      aMap1 = &theOtherMap;
+      aMap2 = &theMap;
+    }
+
+    for (typename MapType::Iterator aIt(*aMap1); aIt.More(); aIt.Next())
+    {
+      if (aMap2->Contains(aIt.Value()))
+      {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
+  //! Sets this Map to be the result of intersection (aka multiplication, common, boolean AND)
+  //! operation between two given Maps. The new Map contains only the values that are
+  //! contained in both map operands. All previous content of this Map is cleared.
+  //! This same map (result of the boolean operation) can also be used as one of operands.
+  template<class MapType>
+  void Intersection(MapType& theMap, const MapType& theLeftMap, const MapType& theRightMap)
+  {
+    if (&theLeftMap == &theRightMap)
+    {
+      theMap.Assign(theLeftMap);
+      return;
+    }
+
+    if (&theMap == &theLeftMap)
+    {
+      MapType aCopy(1, theMap.Allocator());
+      theMap.Exchange(aCopy);
+      Intersection<MapType>(theMap, aCopy, theRightMap);
+      return;
+    }
+    else if (&theMap == &theRightMap)
+    {
+      MapType aCopy(1, theMap.Allocator());
+      theMap.Exchange(aCopy);
+      Intersection<MapType>(theMap, theLeftMap, aCopy);
+      return;
+    }
+
+    theMap.Clear();
+    if (theLeftMap.Extent() < theRightMap.Extent())
+    {
+      for (typename MapType::Iterator anIter(theLeftMap); anIter.More(); anIter.Next())
+      {
+        if (theRightMap.Contains(anIter.Key()))
+        {
+          theMap.Add(anIter.Key());
+        }
+      }
+    }
+    else
+    {
+      for (typename MapType::Iterator anIter(theRightMap); anIter.More(); anIter.Next())
+      {
+        if (theLeftMap.Contains(anIter.Key()))
+        {
+          theMap.Add(anIter.Key());
+        }
+      }
+    }
+  }
+
+  //! Apply to this Map the intersection operation (aka multiplication, common, boolean AND)
+  //! with another (given) Map. The result contains only the values that are contained in
+  //! both this and the given maps. This algorithm is similar to method Intersection().
+  //! Returns True if contents of this map is changed.
+  template<class MapType>
+  bool Intersect(MapType& theMap, const MapType& theOtherMap)
+  {
+    if (&theMap == &theOtherMap || theMap.IsEmpty())
+    {
+      return false;
+    }
+
+    const int anOldExtent = theMap.Extent();
+    Intersection<MapType>(theMap, theMap, theOtherMap);
+    return anOldExtent != theMap.Extent();
+  }
+
+  //! Apply to this Map the subtraction (aka set-theoretic difference, relative complement,
+  //! exclude, cut, boolean NOT) operation with another (given) Map. The result contains
+  //! only the values that were previously contained in this map and not contained in this map.
+  //! This algorithm is similar to method Subtract() with two operands. Returns True if
+  //! contents of this map is changed.
+  template<class MapType>
+  bool Subtract(MapType& theMap, const MapType& theOtherMap)
+  {
+    if (&theMap == &theOtherMap)
+    {
+      if (theMap.IsEmpty())
+      {
+        return false;
+      }
+
+      theMap.Clear();
+      return true;
+    }
+
+    const int anOldExtent = theMap.Extent();
+    for (typename MapType::Iterator anIter(theOtherMap); anIter.More(); anIter.Next())
+    {
+      theMap.Remove(anIter.Key());
+    }
+    return anOldExtent != theMap.Extent();
+  }
+
+  //! Sets this Map to be the result of subtraction (aka set-theoretic difference, relative
+  //! complement, exclude, cut, boolean NOT) operation between two given Maps. The new Map
+  //! contains only the values that are contained in the first map operands and not contained
+  //! in the second one. All previous content of this Map is cleared.
+  template<class MapType>
+  void Subtraction(MapType& theMap, const MapType& theLeftMap, const MapType& theRightMap)
+  {
+    if (&theMap == &theLeftMap)
+    {
+      Subtract<MapType>(theMap, theRightMap);
+      return;
+    }
+    else if (&theMap == &theRightMap)
+    {
+      MapType aCopy(1, theMap.Allocator());
+      theMap.Exchange(aCopy);
+      Subtraction(theMap, theLeftMap, aCopy);
+      return;
+    }
+
+    theMap.Assign(theLeftMap);
+    Subtract<MapType>(theMap, theRightMap);
+  }
+
+  //! Sets this Map to be the result of symmetric difference (aka exclusive disjunction,
+  //! boolean XOR) operation between two given Maps. The new Map contains the values that
+  //! are contained only in the first or the second operand maps but not in both.
+  //! All previous content of this Map is cleared. This map (result of the boolean operation)
+  //! can also be used as one of operands.
+  template<class MapType>
+  void Difference(MapType& theMap, const MapType& theLeftMap, const MapType& theRightMap)
+  {
+    if (&theLeftMap == &theRightMap)
+    {
+      theMap.Clear();
+      return;
+    }
+    else if (&theMap == &theLeftMap)
+    {
+      MapType aCopy(1, theMap.Allocator());
+      theMap.Exchange(aCopy);
+      Difference<MapType>(theMap, aCopy, theRightMap);
+      return;
+    }
+    else if (&theMap == &theRightMap)
+    {
+      MapType aCopy(1, theMap.Allocator());
+      theMap.Exchange(aCopy);
+      Difference<MapType>(theMap, theLeftMap, aCopy);
+      return;
+    }
+
+    theMap.Clear();
+    for (typename MapType::Iterator anIter(theLeftMap); anIter.More(); anIter.Next())
+    {
+      if (!theRightMap.Contains(anIter.Key()))
+      {
+        theMap.Add(anIter.Key());
+      }
+    }
+    for (typename MapType::Iterator anIter(theRightMap); anIter.More(); anIter.Next())
+    {
+      if (!theLeftMap.Contains(anIter.Key()))
+      {
+        theMap.Add(anIter.Key());
+      }
+    }
+  }
+
+  //! Apply to this Map the symmetric difference (aka exclusive disjunction, boolean XOR)
+  //! operation with another (given) Map. The result contains the values that are contained
+  //! only in this or the operand map, but not in both. This algorithm is similar to method
+  //! Difference(). Returns True if contents of this map is changed.
+  template<class MapType>
+  bool Differ(MapType& theMap, const MapType& theOtherMap)
+  {
+    if (&theMap == &theOtherMap)
+    {
+      if (theMap.IsEmpty())
+      {
+        return false;
+      }
+      theMap.Clear();
+      return true;
+    }
+
+    const int anOldExtent = theMap.Extent();
+    Difference<MapType>(theMap, theMap, theOtherMap);
+    return anOldExtent != theMap.Extent();
+  }
+
+  //! Checks if this map contains all keys of another map.
+  //! This function checks if theMap contains all keys of theOtherMap. It first
+  //! checks if the two maps are the same instance or if theOtherMap is empty, in
+  //! which case it returns true. Then it compares the number of elements in both
+  //! maps. If theMap has fewer elements than theOtherMap, it returns false. Finally,
+  //! it iterates through all keys in theOtherMap and checks if each key is present
+  //! in theMap.
+  template<class MapType>
+  bool Contains(const MapType& theMap, const MapType& theOtherMap)
+  {
+    if (&theMap == &theOtherMap || theOtherMap.IsEmpty())
+    {
+      return true;
+    }
+    else if (theMap.Extent() < theOtherMap.Extent())
+    {
+      return false;
+    }
+
+    for (typename MapType::Iterator anIter(theOtherMap); anIter.More(); anIter.Next())
+    {
+      if (!theMap.Contains(anIter.Key()))
+      {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  //! Checks if two maps contain exactly the same keys.
+  //! This function compares the keys of two maps and returns true if they contain
+  //! exactly the same keys. It first checks if the two maps are the same instance,
+  //! in which case it returns true. Then it compares the number of elements in both
+  //! maps. If they are equal, it calls the Contains function to check if all keys
+  //! in theOtherMap are present in theMap.
+  template<class MapType>
+  bool IsEqual(const MapType& theMap, const MapType& theOtherMap)
+  {
+    if (&theMap == &theOtherMap)
+    {
+      return true;
+    }
+    return theMap.Extent() == theOtherMap.Extent() && Contains<MapType>(theMap, theOtherMap);
+  }
+}
+
+#endif // NCollection_MapAlgo_HeaderFile
index 418ea4d0211c20c0e9e57abf3574514873779519..38e389a1dbfac6aaa2d051196a0da0eaecd517b4 100644 (file)
@@ -1424,12 +1424,12 @@ static Standard_Integer OCC24271 (Draw_Interpretor& di,
     aMapRight.Add (aKeyIter);
   }
 
-  QCOMPARE (aMapLeft .Contains (aMapRight), Standard_False);
-  QCOMPARE (aMapRight.Contains (aMapLeft),  Standard_False);
+  QCOMPARE (NCollection_MapAlgo::Contains (aMapLeft, aMapRight), Standard_False);
+  QCOMPARE (NCollection_MapAlgo::Contains (aMapRight, aMapLeft),  Standard_False);
 
   // validate Union operation
   NCollection_Map<Standard_Integer> aMapUnion;
-  aMapUnion.Union (aMapLeft, aMapRight);
+  NCollection_MapAlgo::Union(aMapUnion, aMapLeft, aMapRight);
   QCOMPARE (aMapUnion.Extent(), aRightUpper - aLeftLower + 1);
   for (Standard_Integer aKeyIter = aLeftLower; aKeyIter <= aRightUpper; ++aKeyIter)
   {
@@ -1438,18 +1438,18 @@ static Standard_Integer OCC24271 (Draw_Interpretor& di,
 
   // validate Intersection operation
   NCollection_Map<Standard_Integer> aMapSect;
-  aMapSect.Intersection (aMapLeft, aMapRight);
+  NCollection_MapAlgo::Intersection(aMapSect, aMapLeft, aMapRight);
   QCOMPARE (aMapSect.Extent(), aLeftUpper - aRightLower + 1);
   for (Standard_Integer aKeyIter = aRightLower; aKeyIter <= aLeftUpper; ++aKeyIter)
   {
     QCOMPARE (aMapSect.Contains (aKeyIter), Standard_True);
   }
-  QCOMPARE (aMapLeft .Contains (aMapSect), Standard_True);
-  QCOMPARE (aMapRight.Contains (aMapSect), Standard_True);
+  QCOMPARE (NCollection_MapAlgo::Contains (aMapLeft, aMapSect), Standard_True);
+  QCOMPARE (NCollection_MapAlgo::Contains (aMapRight, aMapSect), Standard_True);
 
   // validate Substruction operation
   NCollection_Map<Standard_Integer> aMapSubsLR;
-  aMapSubsLR.Subtraction (aMapLeft, aMapRight);
+  NCollection_MapAlgo::Subtraction(aMapSubsLR, aMapLeft, aMapRight);
   QCOMPARE (aMapSubsLR.Extent(), aRightLower - aLeftLower);
   for (Standard_Integer aKeyIter = aLeftLower; aKeyIter < aRightLower; ++aKeyIter)
   {
@@ -1457,7 +1457,7 @@ static Standard_Integer OCC24271 (Draw_Interpretor& di,
   }
 
   NCollection_Map<Standard_Integer> aMapSubsRL;
-  aMapSubsRL.Subtraction (aMapRight, aMapLeft);
+  NCollection_MapAlgo::Subtraction(aMapSubsRL, aMapRight, aMapLeft);
   QCOMPARE (aMapSubsRL.Extent(), aRightUpper - aLeftUpper);
   for (Standard_Integer aKeyIter = aLeftUpper + 1; aKeyIter < aRightUpper; ++aKeyIter)
   {
@@ -1466,7 +1466,7 @@ static Standard_Integer OCC24271 (Draw_Interpretor& di,
 
   // validate Difference operation
   NCollection_Map<Standard_Integer> aMapDiff;
-  aMapDiff.Difference (aMapLeft, aMapRight);
+  NCollection_MapAlgo::Difference(aMapDiff, aMapLeft, aMapRight);
   QCOMPARE (aMapDiff.Extent(), aRightLower - aLeftLower + aRightUpper - aLeftUpper);
   for (Standard_Integer aKeyIter = aLeftLower; aKeyIter < aRightLower; ++aKeyIter)
   {
@@ -1489,10 +1489,10 @@ static Standard_Integer OCC24271 (Draw_Interpretor& di,
   aMapSect.Add (43);
 
   NCollection_Map<Standard_Integer> aMapCopy (aMapSwap);
-  QCOMPARE (aMapCopy.IsEqual (aMapSwap), Standard_True);
+  QCOMPARE (NCollection_MapAlgo::IsEqual(aMapCopy, aMapSwap), Standard_True);
   aMapCopy.Remove (34);
   aMapCopy.Add    (43);
-  QCOMPARE (aMapCopy.IsEqual (aMapSwap), Standard_False);
+  QCOMPARE (NCollection_MapAlgo::IsEqual(aMapCopy, aMapSwap), Standard_False);
 
   return 0;
 }
index 40cc1f261a17e6f11a5b14d37bdd3c72061e475d..83c5ac7be14faf0f3cd559ac958838285de2976a 100644 (file)
@@ -401,8 +401,8 @@ static void TestMap(QANCollection_MapFunc& theM, Draw_Interpretor& theDI)
     aM3.Add(2);
     aM3.Add(3);
 
-    if (!aM1.HasIntersection(aM2) || !aM2.HasIntersection(aM1) ||
-         aM1.HasIntersection(aM3) ||  aM3.HasIntersection(aM1))
+    if (!NCollection_MapAlgo::HasIntersection(aM1, aM2) || !NCollection_MapAlgo::HasIntersection(aM2, aM1) ||
+         NCollection_MapAlgo::HasIntersection(aM1, aM3) ||  NCollection_MapAlgo::HasIntersection(aM3, aM1))
     {
       theDI << "Error: method 'HasIntersection' failed.";
     }
index 52e8501c45e96670f3372fd9112c80e6e6d23226..79636cfc70a8c13eadd1f2a03f5244192e4a0505 100644 (file)
@@ -2516,7 +2516,7 @@ Standard_Boolean ShapeUpgrade_UnifySameDomain::MergeEdges(TopTools_SequenceOfSha
       }
     }
   }
-  VerticesToAvoid.Unite(NonMergVrt);
+  NCollection_MapAlgo::Unite(VerticesToAvoid, NonMergVrt);
 
   // do loop while there are unused edges
   TopTools_MapOfShape aUsedEdges;
index f013485533e0e976f2632d80d9d562ac297880ee..e002a678ddd2ae2fb873a8c059087e7e4ec79e93 100644 (file)
@@ -672,7 +672,7 @@ bool XCAFDoc_Editor::FilterShapeTree(const Handle(XCAFDoc_ShapeTool)& theShapeTo
   for (TDF_LabelMap::Iterator aLabelIter (theLabelsToKeep); aLabelIter.More(); aLabelIter.Next())
   {
     GetParentShapeLabels (aLabelIter.Key(), aInternalLabels);
-    aLabelsToKeep.Unite(aInternalLabels);
+    NCollection_MapAlgo::Unite(aLabelsToKeep, aInternalLabels);
     aInternalLabels.Clear(false);
   }
   for(TDF_ChildIterator aLabelIter (theShapeTool->Label(), true); aLabelIter.More(); aLabelIter.Next())