0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / NCollection / NCollection_DefaultHasher.hxx
1 // Created by: Eugene Maltchikov
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef NCollection_DefaultHasher_HeaderFile
16 #define NCollection_DefaultHasher_HeaderFile
17
18 #include <Standard_Integer.hxx>
19 #include <Standard_Boolean.hxx>
20
21 //=======================================================================
22 //function : HashCode_Proxy
23 //purpose  : Function is required to call the global function HashCode.
24 //=======================================================================
25
26 //! Returns hash code for the given key, in the range [1, theUpperBound]
27 //! @tparam TheKeyType the type of the given key
28 //! @param theKey the key which hash code is to be computed
29 //! @param theUpperBound the upper bound of the range a computing hash code must be within
30 //! @return a computed hash code, in the range [1, theUpperBound]
31 template <class TheKeyType>
32 inline Standard_Integer HashCode_Proxy (const TheKeyType& theKey, const Standard_Integer theUpperBound)
33 {
34   return HashCode (theKey, theUpperBound);
35 }
36
37 //=======================================================================
38 //function : IsEqual
39 //purpose  : Default implementation of IsEqual via operator ==
40 //=======================================================================
41
42 template <class TheKeyType> 
43 inline Standard_Boolean IsEqual (const TheKeyType& theKey1, 
44                                  const TheKeyType& theKey2)
45 {
46   return theKey1 == theKey2;
47 }
48
49 //=======================================================================
50 //function : IsEqual_Proxy
51 //purpose  : Function is required to call the global function IsEqual.
52 //=======================================================================
53
54 template <class TheKeyType> 
55 inline Standard_Boolean IsEqual_Proxy (const TheKeyType& theKey1, 
56                                        const TheKeyType& theKey2)
57 {
58   return IsEqual (theKey1, theKey2);
59 }
60
61
62 /**
63  * Purpose:     The  DefaultHasher  is a  Hasher  that is used by
64  *              default in NCollection maps. 
65  *              To compute the  hash code of the key  is used the
66  *              global function HashCode.
67  *              To compare two keys is used  the  global function 
68  *              IsEqual.
69 */
70 template <class TheKeyType> class NCollection_DefaultHasher {
71 public:
72   //! Returns hash code for the given key, in the range [1, theUpperBound]
73   //! @param theKey the key which hash code is to be computed
74   //! @param theUpperBound the upper bound of the range a computing hash code must be within
75   //! @return a computed hash code, in the range [1, theUpperBound]
76   static Standard_Integer HashCode (const TheKeyType& theKey, const Standard_Integer theUpperBound)
77   {
78     return HashCode_Proxy (theKey, theUpperBound);
79   }
80
81   //
82   static Standard_Boolean IsEqual(const TheKeyType& theKey1, 
83                                   const TheKeyType& theKey2) {
84     return IsEqual_Proxy(theKey1, theKey2);
85   }
86 };
87
88 #endif