From 49cadff55d68de0a1149f14d21fefbe972d16869 Mon Sep 17 00:00:00 2001 From: Grey Golla Date: Thu, 22 Feb 2024 18:08:54 -0800 Subject: [PATCH] Fix build errors --- .../fixed_doubly_linked_list.hpp | 3 +- .../fixed_containers/fixed_map_adapter.hpp | 3 +- .../fixed_robinhood_hashtable.hpp | 16 ++++++- .../fixed_containers/fixed_set_adapter.hpp | 2 +- include/fixed_containers/wyhash.hpp | 46 ++++++++++--------- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/include/fixed_containers/fixed_doubly_linked_list.hpp b/include/fixed_containers/fixed_doubly_linked_list.hpp index fb19eada..bb9a45b4 100644 --- a/include/fixed_containers/fixed_doubly_linked_list.hpp +++ b/include/fixed_containers/fixed_doubly_linked_list.hpp @@ -18,6 +18,7 @@ struct LinkedListIndices template class FixedDoublyLinkedListBase { + static_assert(MAXIMUM_SIZE + 1 <= std::numeric_limits::max(), "must be able to index MAXIMUM_SIZE+1 elements with IndexType"); using StorageType = FixedIndexBasedPoolStorage; using ChainEntryType = LinkedListIndices; using ChainType = std::array; @@ -65,7 +66,7 @@ class FixedDoublyLinkedListBase constexpr IndexType emplace_after_index_and_return_index(IndexType idx, Args&&... args) { increment_size(); - IndexType new_idx = storage().emplace_and_return_index(std::forward(args)...); + IndexType new_idx = static_cast(storage().emplace_and_return_index(std::forward(args)...)); next_of(new_idx) = next_of(idx); prev_of(next_of(new_idx)) = new_idx; prev_of(new_idx) = idx; diff --git a/include/fixed_containers/fixed_map_adapter.hpp b/include/fixed_containers/fixed_map_adapter.hpp index 8b3b77e9..2ead51f5 100644 --- a/include/fixed_containers/fixed_map_adapter.hpp +++ b/include/fixed_containers/fixed_map_adapter.hpp @@ -232,7 +232,7 @@ class FixedMapAdapter return {create_iterator(idx), false}; } - check_not_full(std::source_location::current()); + check_not_full(loc); idx = table().emplace(idx, std::move(pair.first), std::move(pair.second)); return {create_iterator(idx), true}; } @@ -496,7 +496,6 @@ class FixedMapAdapter }; - template : IMPLEMENTATION_DETAIL_DO_NOT_USE_hash_(other.IMPLEMENTATION_DETAIL_DO_NOT_USE_hash_) , IMPLEMENTATION_DETAIL_DO_NOT_USE_key_equal_(other.IMPLEMENTATION_DETAIL_DO_NOT_USE_key_equal_) - , IMPLEMENTATION_DETAIL_DO_NOT_USE_bucket_array_(other.IMPLEMENTATION_DETAIL_DO_NOT_USE_bucket_array_) , IMPLEMENTATION_DETAIL_DO_NOT_USE_value_storage_(other.IMPLEMENTATION_DETAIL_DO_NOT_USE_value_storage_) + , IMPLEMENTATION_DETAIL_DO_NOT_USE_bucket_array_(other.IMPLEMENTATION_DETAIL_DO_NOT_USE_bucket_array_) { } constexpr FixedRobinhoodHashtable(const FixedRobinhoodHashtable& other) requires (!IsReference) = default; + + constexpr FixedRobinhoodHashtable& operator=(const FixedRobinhoodHashtable& other) + requires IsReference + { + IMPLEMENTATION_DETAIL_DO_NOT_USE_hash_ = other.IMPLEMENTATION_DETAIL_DO_NOT_USE_hash_; + IMPLEMENTATION_DETAIL_DO_NOT_USE_key_equal_ = other.IMPLEMENTATION_DETAIL_DO_NOT_USE_key_equal_; + IMPLEMENTATION_DETAIL_DO_NOT_USE_value_storage_ = other.IMPLEMENTATION_DETAIL_DO_NOT_USE_value_storage_; + IMPLEMENTATION_DETAIL_DO_NOT_USE_bucket_array_ = other.IMPLEMENTATION_DETAIL_DO_NOT_USE_bucket_array_; + return *this; + } + + constexpr FixedRobinhoodHashtable& operator=(const FixedRobinhoodHashtable& other) requires (!IsReference) = default; }; } // namespace fixed_containers::fixed_robinhood_hashtable_detail diff --git a/include/fixed_containers/fixed_set_adapter.hpp b/include/fixed_containers/fixed_set_adapter.hpp index 300629d0..9ad72def 100644 --- a/include/fixed_containers/fixed_set_adapter.hpp +++ b/include/fixed_containers/fixed_set_adapter.hpp @@ -154,7 +154,7 @@ class FixedSetAdapter return {create_const_iterator(idx), false}; } - check_not_full(std::source_location::current()); + check_not_full(loc); idx = table().emplace(idx, std::move(value)); return {create_const_iterator(idx), true}; } diff --git a/include/fixed_containers/wyhash.hpp b/include/fixed_containers/wyhash.hpp index 76521c61..91ccf741 100644 --- a/include/fixed_containers/wyhash.hpp +++ b/include/fixed_containers/wyhash.hpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include // This is a stripped-down implementation of wyhash: https://github.com/wangyi-fudan/wyhash // No big-endian support (because different values on different machines don't matter), @@ -47,24 +49,24 @@ constexpr inline void mum(std::uint64_t* a, std::uint64_t* b) { } // read functions. WARNING: we don't care about endianness, so results are different on big endian! -[[nodiscard]] constexpr inline auto r8(const std::uint8_t* p) -> std::uint64_t { +[[nodiscard]]inline auto r8(const std::uint8_t* p) -> std::uint64_t { std::uint64_t v{}; std::memcpy(&v, p, 8U); return v; } -[[nodiscard]] constexpr inline auto r4(const std::uint8_t* p) -> std::uint64_t { +[[nodiscard]] inline auto r4(const std::uint8_t* p) -> std::uint64_t { std::uint32_t v{}; std::memcpy(&v, p, 4); return v; } // reads 1, 2, or 3 bytes -[[nodiscard]] constexpr inline auto r3(const std::uint8_t* p, size_t k) -> std::uint64_t { - return (static_cast(p[0]) << 16U) | (static_cast(p[k >> 1U]) << 8U) | p[k - 1]; +[[nodiscard]] inline auto r3(const std::uint8_t* p, ssize_t k) -> std::uint64_t { + return (static_cast(*p) << 16U) | (static_cast(*std::next(p, k >> 1U)) << 8U) | *std::next(p, k - 1); } -[[maybe_unused]] [[nodiscard]] constexpr inline auto hash(void const* key, size_t len) -> std::uint64_t { +[[maybe_unused]] [[nodiscard]] inline auto hash(void const* key, ssize_t len) -> std::uint64_t { constexpr auto secret = std::array{UINT64_C(0xa0761d6478bd642f), UINT64_C(0xe7037ed1a0b428db), UINT64_C(0x8ebc6af09c88c6e3), @@ -76,8 +78,8 @@ constexpr inline void mum(std::uint64_t* a, std::uint64_t* b) { std::uint64_t b{}; if (len <= 16) { if (len >= 4) { - a = (r4(p) << 32U) | r4(p + ((len >> 3U) << 2U)); - b = (r4(p + len - 4) << 32U) | r4(p + len - 4 - ((len >> 3U) << 2U)); + a = (r4(p) << 32U) | r4(std::next(p, (len >> 3U) << 2U)); + b = (r4(std::next(p, len - 4)) << 32U) | r4(std::next(p, len - 4 - ((len >> 3U) << 2U))); } else if (len > 0) { a = r3(p, len); b = 0; @@ -86,29 +88,29 @@ constexpr inline void mum(std::uint64_t* a, std::uint64_t* b) { b = 0; } } else { - size_t i = len; + ssize_t i = len; if (i > 48) { std::uint64_t see1 = seed; std::uint64_t see2 = seed; do { - seed = mix(r8(p) ^ secret[1], r8(p + 8) ^ seed); - see1 = mix(r8(p + 16) ^ secret[2], r8(p + 24) ^ see1); - see2 = mix(r8(p + 32) ^ secret[3], r8(p + 40) ^ see2); - p += 48; + seed = mix(r8(p) ^ secret[1], r8(std::next(p, 8)) ^ seed); + see1 = mix(r8(std::next(p, 16)) ^ secret[2], r8(std::next(p, 24)) ^ see1); + see2 = mix(r8(std::next(p, 32)) ^ secret[3], r8(std::next(p, 40)) ^ see2); + std::advance(p, 48); i -= 48; } while (i > 48); seed ^= see1 ^ see2; } while (i > 16) { - seed = mix(r8(p) ^ secret[1], r8(p + 8) ^ seed); + seed = mix(r8(p) ^ secret[1], r8(std::next(p, 8)) ^ seed); i -= 16; - p += 16; + std::advance(p, 16); } - a = r8(p + i - 16); - b = r8(p + i - 8); + a = r8(std::next(p, i - 16)); + b = r8(std::next(p, i - 8)); } - return mix(secret[1] ^ len, mix(a ^ secret[1], b ^ seed)); + return mix(secret[1] ^ static_cast(len), mix(a ^ secret[1], b ^ seed)); } [[nodiscard]] constexpr inline std::uint64_t hash(std::uint64_t x) @@ -133,21 +135,21 @@ struct hash { template struct hash> { - constexpr std::uint64_t operator()(std::basic_string const& str) const noexcept { - return wyhash_detail::hash(str.data(), sizeof(CharT) * str.size()); + std::uint64_t operator()(std::basic_string const& str) const noexcept { + return wyhash_detail::hash(str.data(), static_cast(sizeof(CharT) * str.size())); } }; template struct hash> { - constexpr std::uint64_t operator()(std::basic_string_view const& sv) const noexcept { - return wyhash_detail::hash(sv.data(), sizeof(CharT) * sv.size()); + std::uint64_t operator()(std::basic_string_view const& sv) const noexcept { + return wyhash_detail::hash(sv.data(), static_cast(sizeof(CharT) * sv.size())); } }; template struct hash { - constexpr std::uint64_t operator()(T* ptr) const noexcept { + std::uint64_t operator()(T* ptr) const noexcept { return wyhash_detail::hash(reinterpret_cast(ptr)); } };