Fix a bug with Map
This commit is contained in:
@ -23,6 +23,11 @@ namespace ia
|
|||||||
template<typename _type>
|
template<typename _type>
|
||||||
concept hashable_type = std::derived_from<_type, IIHashable>;
|
concept hashable_type = std::derived_from<_type, IIHashable>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept comparible_type = requires(T a, T b) {
|
||||||
|
{ a == b } -> std::same_as<bool>;
|
||||||
|
};
|
||||||
|
|
||||||
INLINE UINT64 IIHashable::fnv_1a(IN PCUINT8 data, IN SIZE_T dataLength)
|
INLINE UINT64 IIHashable::fnv_1a(IN PCUINT8 data, IN SIZE_T dataLength)
|
||||||
{
|
{
|
||||||
// Implemented as described at http://isthe.com/chongo/tech/comp/fnv/#google_vignette
|
// Implemented as described at http://isthe.com/chongo/tech/comp/fnv/#google_vignette
|
||||||
@ -34,4 +39,4 @@ namespace ia
|
|||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
} // namespace ia
|
||||||
@ -23,7 +23,7 @@
|
|||||||
namespace ia
|
namespace ia
|
||||||
{
|
{
|
||||||
template<typename _key_type, typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
|
template<typename _key_type, typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
|
||||||
requires hashable_type<_key_type> && valid_allocator_type<_allocator_type, _value_type>
|
requires (hashable_type<_key_type> || std::is_integral_v<_key_type>) && valid_allocator_type<_allocator_type, _value_type>
|
||||||
class Map
|
class Map
|
||||||
{
|
{
|
||||||
STATIC CONSTEXPR SIZE_T BUCKET_COUNT = 1000;
|
STATIC CONSTEXPR SIZE_T BUCKET_COUNT = 1000;
|
||||||
|
|||||||
@ -18,10 +18,14 @@
|
|||||||
|
|
||||||
#include "interface/map.interface.inl"
|
#include "interface/map.interface.inl"
|
||||||
|
|
||||||
#define __template template<typename _key_type, typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires hashable_type<_key_type> && valid_allocator_type<_allocator_type, _value_type>
|
#define __template \
|
||||||
|
template<typename _key_type, typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> \
|
||||||
|
requires(hashable_type<_key_type> || std::is_integral_v<_key_type>) && \
|
||||||
|
valid_allocator_type<_allocator_type, _value_type>
|
||||||
#define __ia_identifier Map<_key_type, _value_type, _allocator_type, _alignment>
|
#define __ia_identifier Map<_key_type, _value_type, _allocator_type, _alignment>
|
||||||
#define define_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__)
|
#define define_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__)
|
||||||
#define define_const_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__) CONST
|
#define define_const_member_function(return_type, name, ...) \
|
||||||
|
__template return_type __ia_identifier::name(__VA_ARGS__) CONST
|
||||||
|
|
||||||
namespace ia
|
namespace ia
|
||||||
{
|
{
|
||||||
@ -33,7 +37,7 @@ namespace ia
|
|||||||
define_member_function(, ~Map, )
|
define_member_function(, ~Map, )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
} // namespace ia
|
||||||
|
|
||||||
namespace ia
|
namespace ia
|
||||||
{
|
{
|
||||||
@ -64,20 +68,27 @@ namespace ia
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} // namespace ia
|
||||||
|
|
||||||
namespace ia
|
namespace ia
|
||||||
{
|
{
|
||||||
define_member_function(List<typename __ia_identifier::KeyValuePair> &, getBucket, IN CONST key_type &key)
|
define_member_function(List<typename __ia_identifier::KeyValuePair> &, getBucket, IN CONST key_type &key)
|
||||||
{
|
{
|
||||||
|
if constexpr (std::is_integral_v<key_type>)
|
||||||
|
return m_buckets[key % BUCKET_COUNT];
|
||||||
|
else
|
||||||
return m_buckets[key.hash() % BUCKET_COUNT];
|
return m_buckets[key.hash() % BUCKET_COUNT];
|
||||||
}
|
}
|
||||||
|
|
||||||
define_const_member_function(CONST List<typename __ia_identifier::KeyValuePair>&, getBucket, IN CONST key_type& key)
|
define_const_member_function(CONST List<typename __ia_identifier::KeyValuePair> &, getBucket,
|
||||||
|
IN CONST key_type &key)
|
||||||
{
|
{
|
||||||
|
if constexpr (std::is_integral_v<key_type>)
|
||||||
|
return m_buckets[key % BUCKET_COUNT];
|
||||||
|
else
|
||||||
return m_buckets[key.hash() % BUCKET_COUNT];
|
return m_buckets[key.hash() % BUCKET_COUNT];
|
||||||
}
|
}
|
||||||
}
|
} // namespace ia
|
||||||
|
|
||||||
#undef __template
|
#undef __template
|
||||||
#undef __ia_identifier
|
#undef __ia_identifier
|
||||||
|
|||||||
Reference in New Issue
Block a user