[*] Finally enable independent string allocators

This commit is contained in:
Reece Wilson 2024-04-20 01:14:34 +01:00
parent b3e0a6df31
commit f2acc55b42
5 changed files with 59 additions and 20 deletions

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#include "auFNV1Utils.hpp" #include "auFNV1Utils.hpp"
#include "auMemoryModel.hpp"
#define _AU_HASH_UTILS_HAS_STD #define _AU_HASH_UTILS_HAS_STD
@ -256,6 +257,17 @@ namespace AuHash
return lhs == rhs; return lhs == rhs;
} }
}; };
template <>
struct equal<std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>>
{
using is_transparent = void;
bool operator()(std::string_view lhs, std::string_view rhs) const
{
return lhs == rhs;
}
};
} }
template <class T, AU_TEMPLATE_ENABLE_WHEN(AuHasHashCode_v<T>)> template <class T, AU_TEMPLATE_ENABLE_WHEN(AuHasHashCode_v<T>)>
@ -322,6 +334,18 @@ namespace AuHash
} }
}; };
template <>
struct hash<std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>>
{
using is_transparent = void;
using transparent_key_equal = equal<std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>>;
size_t operator()(std::string_view txt) const
{
return hash<std::string_view>{}(txt);
}
};
template <> template <>
struct less<std::string> struct less<std::string>
{ {
@ -337,6 +361,21 @@ namespace AuHash
} }
}; };
template <>
struct less<std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>>
{
using is_transparent = void;
bool operator()(std::string_view lhs, std::string_view rhs) const
{
#if 0
return AuFnv1aRuntime(lhs.data(), lhs.size()) < AuFnv1aRuntime(rhs.data(), rhs.size());
#else
return hash<std::string_view>{}(lhs) < hash<std::string_view>{}(rhs);
#endif
}
};
template <> template <>
struct less<std::string_view> struct less<std::string_view>
{ {
@ -381,3 +420,19 @@ struct AuEnableHashCodeOnData
#undef _AU_HASH_RETARD_COMPILER #undef _AU_HASH_RETARD_COMPILER
#undef _AH_HAS_RETARD_CONSTEXPR #undef _AH_HAS_RETARD_CONSTEXPR
#endif #endif
namespace AuHash
{
template <class T>
struct hash<AuSPtr<T>>
{
AuUInt operator ()(const AuSPtr<T> &ptr) const
{
#if defined(AURORA_IS_32BIT)
return ComputeUnseededHash(AuUInt(ptr.get()));
#else
return ComputeLongHash(AuUInt(ptr.get()));
#endif
}
};
}

View File

@ -310,19 +310,3 @@ namespace Aurora::Memory
#endif #endif
} }
namespace AuHash
{
template <class T>
struct hash<AuSPtr<T>>
{
AuUInt operator ()(const AuSPtr<T> &ptr) const
{
#if defined(AURORA_IS_32BIT)
return ComputeUnseededHash(AuUInt(ptr.get()));
#else
return ComputeLongHash(AuUInt(ptr.get()));
#endif
}
};
}

View File

@ -8,7 +8,6 @@
#pragma once #pragma once
#include "auCopyMoveUtils.hpp" #include "auCopyMoveUtils.hpp"
#include "auHashUtils.hpp"
template <class T> template <class T>
struct AuResult struct AuResult

View File

@ -15,5 +15,6 @@
#elif defined(AURORA_ROXTL_STRING_USE_STR_ALLOCATOR) #elif defined(AURORA_ROXTL_STRING_USE_STR_ALLOCATOR)
using AuString = std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>; using AuString = std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>;
#else #else
using AuString = std::string; using AuString = std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>;
//using AuString = std::string;
#endif #endif

View File

@ -1047,7 +1047,7 @@ static auline AuString AuToString(const T &obj)
{ {
#if defined(_AUHAS_FMT) #if defined(_AUHAS_FMT)
// locale independent and better optimized! // locale independent and better optimized!
return fmt::format("{}", obj); return AuString(fmt::format("{}", obj));
#else #else
// TODO: to_chars (locale independent) // TODO: to_chars (locale independent)
return AURORA_RUNTIME_TO_STRING(obj); return AURORA_RUNTIME_TO_STRING(obj);