Version: 9.15.0
SVTK_Hash.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2025 CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // SALOME SALOMEGUI :
24 // File : SVTK_Hash.h
25 // Author : Roman NIKOLAEV
26 
27 #ifndef SVTK_HASH_H
28 #define SVTK_HASH_H
29 
30 #include <vector>
31 #include <NCollection_IndexedMap.hxx>
32 #include <NCollection_Map.hxx>
33 #include <Standard_Integer.hxx>
34 #include <vtkType.h>
35 #include <limits>
36 
37 #include <Basics_OCCTVersion.hxx>
38 
39 typedef std::vector<Standard_Integer> SVTK_ListOfInteger;
40 typedef std::vector<vtkIdType> SVTK_ListOfVtk;
41 
42 #if OCC_VERSION_LARGE < 0x07080000
43 class SVTK_Hasher {
44 
45 public:
46  static Standard_Integer HashCode(const std::vector<Standard_Integer> ids,
47  const Standard_Integer upper)
48  {
49  Standard_Integer seed = (Standard_Integer)ids.size();
50  for ( Standard_Integer v : ids )
51  seed ^= v + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
52 
53  return ::HashCode(seed,upper);
54  }
55 
56  static Standard_Boolean IsEqual(const SVTK_ListOfInteger& theKey1,
57  const SVTK_ListOfInteger& theKey2)
58  {
59  return theKey1 == theKey2;
60  }
61 };
62 
64 
65 public:
66  static vtkIdType HashCode(const std::vector<vtkIdType> ids,
67  const Standard_Integer upper)
68  {
69  vtkIdType seed = (vtkIdType)ids.size();
70  for ( vtkIdType v : ids )
71  seed ^= v + 0x9e3779b97f4a7c15 + ( seed << 6 ) + ( seed >> 2 );
72 
73  return ::HashCode((Standard_Integer) seed, upper);
74  }
75 
76  static vtkIdType IsEqual(const SVTK_ListOfVtk& theKey1,
77  const SVTK_ListOfVtk& theKey2)
78  {
79  return theKey1 == theKey2;
80  }
81 };
82 
84 {
85  static int HashCode(const vtkIdType theValue, const int theUpperBound)
86  {
87  return static_cast<int> ((theValue & (std::numeric_limits<vtkIdType>::max)()) % theUpperBound + 1);
88  }
89 
90  static bool IsEqual( const vtkIdType& id1, const vtkIdType& id2 )
91  {
92  return id1 == id2;
93  }
94 };
95 
96 #else
97 
98 class SVTK_Hasher {
99 
100 public:
101  size_t operator()(const std::vector<Standard_Integer> ids) const
102  {
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());
107  }
108 
109  bool operator()(const SVTK_ListOfInteger& theKey1,
110  const SVTK_ListOfInteger& theKey2) const
111  {
112  return theKey1 == theKey2;
113  }
114 };
115 
116 class SVTK_vtkHasher {
117 
118 public:
119  size_t operator()(const std::vector<vtkIdType> ids) const
120  {
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)());
125  }
126 
127  bool operator()(const SVTK_ListOfVtk& theKey1,
128  const SVTK_ListOfVtk& theKey2) const
129  {
130  return theKey1 == theKey2;
131  }
132 };
133 
134 struct svtkIdHasher
135 {
136  size_t operator()(const vtkIdType theValue) const
137  {
138  return (size_t)(theValue & (std::numeric_limits<vtkIdType>::max)());
139  }
140 
141  bool operator()(const vtkIdType& id1, const vtkIdType& id2) const
142  {
143  return id1 == id2;
144  }
145 };
146 
147 #endif // OCC_VERSION_LARGE < 0x07080000
148 
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;
154 
155 #endif // SVTK_HASH_H
NCollection_Map< vtkIdType, svtkIdHasher > SVTK_TVtkIDsMap
Definition: SVTK_Hash.h:151
NCollection_IndexedMap< SVTK_ListOfVtk, SVTK_vtkHasher > SVTK_IndexedMapOfVtkIds
Definition: SVTK_Hash.h:150
std::vector< vtkIdType > SVTK_ListOfVtk
Definition: SVTK_Hash.h:40
std::vector< Standard_Integer > SVTK_ListOfInteger
Definition: SVTK_Hash.h:39
NCollection_Map< vtkIdType, svtkIdHasher >::Iterator SVTK_TVtkIDsMapIterator
Definition: SVTK_Hash.h:152
NCollection_IndexedMap< vtkIdType, svtkIdHasher > SVTK_TIndexedMapOfVtkId
Definition: SVTK_Hash.h:153
NCollection_IndexedMap< SVTK_ListOfInteger, SVTK_Hasher > SVTK_IndexedMapOfIds
Definition: SVTK_Hash.h:149
Definition: SVTK_Hash.h:43
static Standard_Integer HashCode(const std::vector< Standard_Integer > ids, const Standard_Integer upper)
Definition: SVTK_Hash.h:46
static Standard_Boolean IsEqual(const SVTK_ListOfInteger &theKey1, const SVTK_ListOfInteger &theKey2)
Definition: SVTK_Hash.h:56
Definition: SVTK_Hash.h:63
static vtkIdType HashCode(const std::vector< vtkIdType > ids, const Standard_Integer upper)
Definition: SVTK_Hash.h:66
static vtkIdType IsEqual(const SVTK_ListOfVtk &theKey1, const SVTK_ListOfVtk &theKey2)
Definition: SVTK_Hash.h:76
Definition: SVTK_Hash.h:84
static bool IsEqual(const vtkIdType &id1, const vtkIdType &id2)
Definition: SVTK_Hash.h:90
static int HashCode(const vtkIdType theValue, const int theUpperBound)
Definition: SVTK_Hash.h:85