mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0033370: Foundation Classes - Moving into STL and Boost functionality
NCollection containers update: - NCollection_Array1 - updated functionality - NCollection_Array2 - NCollection_Array1 as a wrapper for 2array - NCollection_Vector -> NCollection_DynamicArray was renamed and reworked. TCollection: - Use static empty string to avoid allocations on empty string NCollection allocators update: - NCollection_Allocator - allocator that used Standard::Allocate - NCollection_OccAllocator - allocator-wrapper that used OCC BaseAllocator objects - NCollection_IncAllocator - rework to increase performance Standard: - Rework functionality to use different allocation libs - Implement basic of new way to wrap allocations tools - Define 4 ways to allocation (defines in configure stage) Additional changes: - Hash function uses std::hash functionality - size_t as a hash value - New HashUtils with Murmur and FVN hash algo for x32 and x64 - Deprecated _0.cxx and .gxx DE classes reorganized - Create own utility for std memory - Update Standard_Transient to be more platform-independent Math TK changes: - math_Vector -> match_BaseVector<> - Buffer decreased to cash 32 elements instead of 512
This commit is contained in:
@@ -15,72 +15,95 @@
|
||||
#ifndef NCollection_DefaultHasher_HeaderFile
|
||||
#define NCollection_DefaultHasher_HeaderFile
|
||||
|
||||
#include <Standard_Integer.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : HashCode_Proxy
|
||||
//purpose : Function is required to call the global function HashCode.
|
||||
//=======================================================================
|
||||
|
||||
//! Returns hash code for the given key, in the range [1, theUpperBound]
|
||||
//! @tparam TheKeyType the type of the given key
|
||||
//! @param theKey the key which hash code is to be computed
|
||||
//! @param theUpperBound the upper bound of the range a computing hash code must be within
|
||||
//! @return a computed hash code, in the range [1, theUpperBound]
|
||||
template <class TheKeyType>
|
||||
inline Standard_Integer HashCode_Proxy (const TheKeyType& theKey, const Standard_Integer theUpperBound)
|
||||
{
|
||||
return HashCode (theKey, theUpperBound);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsEqual
|
||||
//purpose : Default implementation of IsEqual via operator ==
|
||||
//=======================================================================
|
||||
|
||||
template <class TheKeyType>
|
||||
inline Standard_Boolean IsEqual (const TheKeyType& theKey1,
|
||||
const TheKeyType& theKey2)
|
||||
{
|
||||
return theKey1 == theKey2;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsEqual_Proxy
|
||||
//purpose : Function is required to call the global function IsEqual.
|
||||
//=======================================================================
|
||||
|
||||
template <class TheKeyType>
|
||||
inline Standard_Boolean IsEqual_Proxy (const TheKeyType& theKey1,
|
||||
const TheKeyType& theKey2)
|
||||
{
|
||||
return IsEqual (theKey1, theKey2);
|
||||
}
|
||||
#include <functional>
|
||||
|
||||
#include <Standard_HashUtils.hxx>
|
||||
#include <NCollection_DefineHasher.hxx>
|
||||
|
||||
/**
|
||||
* Purpose: The DefaultHasher is a Hasher that is used by
|
||||
* default in NCollection maps.
|
||||
* default in NCollection maps.
|
||||
* To compute the hash code of the key is used the
|
||||
* global function HashCode.
|
||||
* To compare two keys is used the global function
|
||||
* IsEqual.
|
||||
*/
|
||||
template <class TheKeyType> class NCollection_DefaultHasher {
|
||||
public:
|
||||
//! Returns hash code for the given key, in the range [1, theUpperBound]
|
||||
//! @param theKey the key which hash code is to be computed
|
||||
//! @param theUpperBound the upper bound of the range a computing hash code must be within
|
||||
//! @return a computed hash code, in the range [1, theUpperBound]
|
||||
static Standard_Integer HashCode (const TheKeyType& theKey, const Standard_Integer theUpperBound)
|
||||
template <class TheKeyType>
|
||||
DEFINE_HASHER(NCollection_DefaultHasher, TheKeyType, std::hash<TheKeyType>, std::equal_to<TheKeyType>)
|
||||
|
||||
|
||||
#define DEFINE_DEFAULT_HASHER_PURE(TheKeyType) \
|
||||
template <> struct NCollection_DefaultHasher<TheKeyType> \
|
||||
{ \
|
||||
size_t operator()(const TheKeyType theKey) const noexcept \
|
||||
{ \
|
||||
return static_cast<size_t>(theKey); \
|
||||
} \
|
||||
\
|
||||
bool operator() (const TheKeyType theK1, \
|
||||
const TheKeyType theK2) const noexcept \
|
||||
{ \
|
||||
return theK1 == theK2; \
|
||||
} \
|
||||
};
|
||||
|
||||
/// Explicit specialization for bool.
|
||||
DEFINE_DEFAULT_HASHER_PURE(bool)
|
||||
|
||||
/// Explicit specialization for char.
|
||||
DEFINE_DEFAULT_HASHER_PURE(char)
|
||||
|
||||
/// Explicit specialization for signed char.
|
||||
DEFINE_DEFAULT_HASHER_PURE(signed char)
|
||||
|
||||
/// Explicit specialization for unsigned char.
|
||||
DEFINE_DEFAULT_HASHER_PURE(unsigned char)
|
||||
|
||||
/// Explicit specialization for wchar_t.
|
||||
DEFINE_DEFAULT_HASHER_PURE(wchar_t)
|
||||
|
||||
/// Explicit specialization for char16_t.
|
||||
DEFINE_DEFAULT_HASHER_PURE(char16_t)
|
||||
|
||||
/// Explicit specialization for char32_t.
|
||||
DEFINE_DEFAULT_HASHER_PURE(char32_t)
|
||||
|
||||
/// Explicit specialization for short.
|
||||
DEFINE_DEFAULT_HASHER_PURE(short)
|
||||
|
||||
/// Explicit specialization for int.
|
||||
DEFINE_DEFAULT_HASHER_PURE(int)
|
||||
|
||||
/// Explicit specialization for long.
|
||||
DEFINE_DEFAULT_HASHER_PURE(long)
|
||||
|
||||
/// Explicit specialization for long long.
|
||||
DEFINE_DEFAULT_HASHER_PURE(long long)
|
||||
|
||||
/// Explicit specialization for unsigned short.
|
||||
DEFINE_DEFAULT_HASHER_PURE(unsigned short)
|
||||
|
||||
/// Explicit specialization for unsigned int.
|
||||
DEFINE_DEFAULT_HASHER_PURE(unsigned int)
|
||||
|
||||
/// Explicit specialization for unsigned long.
|
||||
DEFINE_DEFAULT_HASHER_PURE(unsigned long)
|
||||
|
||||
/// Explicit specialization for unsigned long long.
|
||||
DEFINE_DEFAULT_HASHER_PURE(unsigned long long)
|
||||
|
||||
/// Explicit specialization for pointer.
|
||||
template <class TheKeyType>
|
||||
struct NCollection_DefaultHasher<TheKeyType*>
|
||||
{
|
||||
size_t operator()(const TheKeyType* theKey) const noexcept
|
||||
{
|
||||
return HashCode_Proxy (theKey, theUpperBound);
|
||||
return static_cast<size_t>(reinterpret_cast<std::uintptr_t>(theKey));
|
||||
}
|
||||
|
||||
//
|
||||
static Standard_Boolean IsEqual(const TheKeyType& theKey1,
|
||||
const TheKeyType& theKey2) {
|
||||
return IsEqual_Proxy(theKey1, theKey2);
|
||||
bool operator() (const TheKeyType* theK1, const TheKeyType* theK2) const noexcept
|
||||
{
|
||||
return theK1 == theK2;
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user