b311480e |
1 | // Created by: Eugene Maltchikov |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
9991c9c2 |
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 | //======================================================================= |
e3a6386d |
25 | |
2b2be3fb |
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) |
e3a6386d |
33 | { |
2b2be3fb |
34 | return HashCode (theKey, theUpperBound); |
e3a6386d |
35 | } |
36 | |
37 | //======================================================================= |
38 | //function : IsEqual |
39 | //purpose : Default implementation of IsEqual via operator == |
40 | //======================================================================= |
41 | |
9991c9c2 |
42 | template <class TheKeyType> |
e3a6386d |
43 | inline Standard_Boolean IsEqual (const TheKeyType& theKey1, |
44 | const TheKeyType& theKey2) |
45 | { |
46 | return theKey1 == theKey2; |
9991c9c2 |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : IsEqual_Proxy |
51 | //purpose : Function is required to call the global function IsEqual. |
52 | //======================================================================= |
e3a6386d |
53 | |
9991c9c2 |
54 | template <class TheKeyType> |
e3a6386d |
55 | inline Standard_Boolean IsEqual_Proxy (const TheKeyType& theKey1, |
56 | const TheKeyType& theKey2) |
57 | { |
58 | return IsEqual (theKey1, theKey2); |
9991c9c2 |
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: |
2b2be3fb |
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); |
9991c9c2 |
79 | } |
2b2be3fb |
80 | |
9991c9c2 |
81 | // |
82 | static Standard_Boolean IsEqual(const TheKeyType& theKey1, |
83 | const TheKeyType& theKey2) { |
84 | return IsEqual_Proxy(theKey1, theKey2); |
85 | } |
86 | }; |
87 | |
88 | #endif |