1 // Copyright (C) 2007-2024 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 #include <Basics_OCCTVersion.hxx>
39 typedef std::vector<Standard_Integer> SVTK_ListOfInteger;
40 typedef std::vector<vtkIdType> SVTK_ListOfVtk;
42 #if OCC_VERSION_LARGE < 0x07080000
46 static Standard_Integer HashCode(const std::vector<Standard_Integer> ids,
47 const Standard_Integer upper)
49 Standard_Integer seed = (Standard_Integer)ids.size();
50 for ( Standard_Integer v : ids )
51 seed ^= v + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
53 return ::HashCode(seed,upper);
56 static Standard_Boolean IsEqual(const SVTK_ListOfInteger& theKey1,
57 const SVTK_ListOfInteger& theKey2)
59 return theKey1 == theKey2;
63 class SVTK_vtkHasher {
66 static vtkIdType HashCode(const std::vector<vtkIdType> ids,
67 const Standard_Integer upper)
69 vtkIdType seed = (vtkIdType)ids.size();
70 for ( vtkIdType v : ids )
71 seed ^= v + 0x9e3779b97f4a7c15 + ( seed << 6 ) + ( seed >> 2 );
73 return ::HashCode((Standard_Integer) seed, upper);
76 static vtkIdType IsEqual(const SVTK_ListOfVtk& theKey1,
77 const SVTK_ListOfVtk& theKey2)
79 return theKey1 == theKey2;
85 static int HashCode(const vtkIdType theValue, const int theUpperBound)
87 return static_cast<int> ((theValue & (std::numeric_limits<vtkIdType>::max)()) % theUpperBound + 1);
90 static bool IsEqual( const vtkIdType& id1, const vtkIdType& id2 )
101 size_t operator()(const std::vector<Standard_Integer> ids) const
103 Standard_Integer seed = (Standard_Integer)ids.size();
104 for ( Standard_Integer v : ids )
105 seed ^= v + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
106 return (size_t)(seed & IntegerLast());
109 bool operator()(const SVTK_ListOfInteger& theKey1,
110 const SVTK_ListOfInteger& theKey2) const
112 return theKey1 == theKey2;
116 class SVTK_vtkHasher {
119 size_t operator()(const std::vector<vtkIdType> ids) const
121 vtkIdType seed = (vtkIdType)ids.size();
122 for ( vtkIdType v : ids )
123 seed ^= v + 0x9e3779b97f4a7c15 + ( seed << 6 ) + ( seed >> 2 );
124 return (size_t)(seed & (std::numeric_limits<vtkIdType>::max)());
127 bool operator()(const SVTK_ListOfVtk& theKey1,
128 const SVTK_ListOfVtk& theKey2) const
130 return theKey1 == theKey2;
136 size_t operator()(const vtkIdType theValue) const
138 return (size_t)(theValue & (std::numeric_limits<vtkIdType>::max)());
141 bool operator()(const vtkIdType& id1, const vtkIdType& id2) const
147 #endif // OCC_VERSION_LARGE < 0x07080000
149 typedef NCollection_IndexedMap<SVTK_ListOfInteger,SVTK_Hasher> SVTK_IndexedMapOfIds;
150 typedef NCollection_IndexedMap<SVTK_ListOfVtk, SVTK_vtkHasher> SVTK_IndexedMapOfVtkIds;
151 typedef NCollection_Map< vtkIdType, svtkIdHasher > SVTK_TVtkIDsMap;
152 typedef NCollection_Map< vtkIdType, svtkIdHasher >::Iterator SVTK_TVtkIDsMapIterator;
153 typedef NCollection_IndexedMap<vtkIdType,svtkIdHasher> SVTK_TIndexedMapOfVtkId;
155 #endif // SVTK_HASH_H