1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 // Author : Roman NIKOLAEV
31 #include <NCollection_IndexedMap.hxx>
32 #include <NCollection_Map.hxx>
33 #include <Standard_Integer.hxx>
37 typedef std::vector<Standard_Integer> SVTK_ListOfInteger;
38 typedef std::vector<vtkIdType> SVTK_ListOfVtk;
43 static Standard_Integer HashCode(const std::vector<Standard_Integer> ids,
44 const Standard_Integer upper)
46 Standard_Integer seed = (Standard_Integer)ids.size();
47 for ( Standard_Integer v : ids )
48 seed ^= v + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
50 return ::HashCode(seed,upper);
53 static Standard_Boolean IsEqual(const SVTK_ListOfInteger& theKey1,
54 const SVTK_ListOfInteger& theKey2)
56 return theKey1 == theKey2;
60 class SVTK_vtkHasher {
63 static vtkIdType HashCode(const std::vector<vtkIdType> ids,
64 const Standard_Integer upper)
66 vtkIdType seed = (vtkIdType)ids.size();
67 for ( vtkIdType v : ids )
68 seed ^= v + 0x9e3779b97f4a7c15 + ( seed << 6 ) + ( seed >> 2 );
70 return ::HashCode((Standard_Integer) seed, upper);
73 static vtkIdType IsEqual(const SVTK_ListOfVtk& theKey1,
74 const SVTK_ListOfVtk& theKey2)
76 return theKey1 == theKey2;
82 static int HashCode(const vtkIdType theValue, const int theUpperBound)
84 return static_cast<int> ((theValue & (std::numeric_limits<vtkIdType>::max)()) % theUpperBound + 1);
87 static bool IsEqual( const vtkIdType& id1, const vtkIdType& id2 )
93 typedef NCollection_IndexedMap<SVTK_ListOfInteger,SVTK_Hasher> SVTK_IndexedMapOfIds;
94 typedef NCollection_IndexedMap<SVTK_ListOfVtk, SVTK_vtkHasher> SVTK_IndexedMapOfVtkIds;
95 typedef NCollection_Map< vtkIdType, svtkIdHasher > SVTK_TVtkIDsMap;
96 typedef NCollection_Map< vtkIdType, svtkIdHasher >::Iterator SVTK_TVtkIDsMapIterator;
97 typedef NCollection_IndexedMap<vtkIdType,svtkIdHasher> SVTK_TIndexedMapOfVtkId;