1 // Created by: Eugene Maltchikov
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef NCollection_DefaultHasher_HeaderFile
16 #define NCollection_DefaultHasher_HeaderFile
18 #include <Standard_Integer.hxx>
19 #include <Standard_Boolean.hxx>
21 //=======================================================================
22 //function : HashCode_Proxy
23 //purpose : Function is required to call the global function HashCode.
24 //=======================================================================
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)
34 return HashCode (theKey, theUpperBound);
37 //=======================================================================
39 //purpose : Default implementation of IsEqual via operator ==
40 //=======================================================================
42 template <class TheKeyType>
43 inline Standard_Boolean IsEqual (const TheKeyType& theKey1,
44 const TheKeyType& theKey2)
46 return theKey1 == theKey2;
49 //=======================================================================
50 //function : IsEqual_Proxy
51 //purpose : Function is required to call the global function IsEqual.
52 //=======================================================================
54 template <class TheKeyType>
55 inline Standard_Boolean IsEqual_Proxy (const TheKeyType& theKey1,
56 const TheKeyType& theKey2)
58 return IsEqual (theKey1, theKey2);
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
70 template <class TheKeyType> class NCollection_DefaultHasher {
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)
78 return HashCode_Proxy (theKey, theUpperBound);
82 static Standard_Boolean IsEqual(const TheKeyType& theKey1,
83 const TheKeyType& theKey2) {
84 return IsEqual_Proxy(theKey1, theKey2);