Skip to content

Commit

Permalink
Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobobalink committed Feb 23, 2024
1 parent 8bcd78f commit 49cadff
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
3 changes: 2 additions & 1 deletion include/fixed_containers/fixed_doubly_linked_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct LinkedListIndices
template <typename T, std::size_t MAXIMUM_SIZE, typename IndexType = std::size_t>
class FixedDoublyLinkedListBase
{
static_assert(MAXIMUM_SIZE + 1 <= std::numeric_limits<IndexType>::max(), "must be able to index MAXIMUM_SIZE+1 elements with IndexType");
using StorageType = FixedIndexBasedPoolStorage<T, MAXIMUM_SIZE>;
using ChainEntryType = LinkedListIndices<IndexType>;
using ChainType = std::array<ChainEntryType, MAXIMUM_SIZE + 1>;
Expand Down Expand Up @@ -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>(args)...);
IndexType new_idx = static_cast<IndexType>(storage().emplace_and_return_index(std::forward<Args>(args)...));
next_of(new_idx) = next_of(idx);
prev_of(next_of(new_idx)) = new_idx;
prev_of(new_idx) = idx;
Expand Down
3 changes: 1 addition & 2 deletions include/fixed_containers/fixed_map_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down Expand Up @@ -496,7 +496,6 @@ class FixedMapAdapter

};


template <typename K,
typename V,
typename TableImpl,
Expand Down
16 changes: 14 additions & 2 deletions include/fixed_containers/fixed_robinhood_hashtable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct Bucket {
static constexpr DistAndFingerprintType FINGERPRINT_MASK = DIST_INC - 1;

// we can only track a bucket this far away from its ideal location. In a pathological worst case, every bucket is a collision so we can only guarnatee correct behavior up to this bucket count.
static constexpr std::size_t MAX_NUM_BUCKETS = 1U << (sizeof(DistAndFingerprintType) * 8 - FINGERPRINT_BITS) - 1;
static constexpr std::size_t MAX_NUM_BUCKETS = (1U << (sizeof(DistAndFingerprintType) * 8 - FINGERPRINT_BITS)) - 1;

DistAndFingerprintType dist_and_fingerprint_;
ValueIndexType value_index_;
Expand Down Expand Up @@ -334,11 +334,23 @@ class FixedRobinhoodHashtable
requires IsReference<V>
: 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<V>) = default;

constexpr FixedRobinhoodHashtable& operator=(const FixedRobinhoodHashtable& other)
requires IsReference<V>
{
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<V>) = default;
};

} // namespace fixed_containers::fixed_robinhood_hashtable_detail
2 changes: 1 addition & 1 deletion include/fixed_containers/fixed_set_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down
46 changes: 24 additions & 22 deletions include/fixed_containers/wyhash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <functional>
#include <cstring>
#include <memory>
#include <span>
#include <iterator>

// 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),
Expand Down Expand Up @@ -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<std::uint64_t>(p[0]) << 16U) | (static_cast<std::uint64_t>(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<std::uint64_t>(*p) << 16U) | (static_cast<std::uint64_t>(*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),
Expand All @@ -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;
Expand All @@ -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<std::uint64_t>(len), mix(a ^ secret[1], b ^ seed));
}

[[nodiscard]] constexpr inline std::uint64_t hash(std::uint64_t x)
Expand All @@ -133,21 +135,21 @@ struct hash {

template <typename CharT>
struct hash<std::basic_string<CharT>> {
constexpr std::uint64_t operator()(std::basic_string<CharT> const& str) const noexcept {
return wyhash_detail::hash(str.data(), sizeof(CharT) * str.size());
std::uint64_t operator()(std::basic_string<CharT> const& str) const noexcept {
return wyhash_detail::hash(str.data(), static_cast<ssize_t>(sizeof(CharT) * str.size()));
}
};

template <typename CharT>
struct hash<std::basic_string_view<CharT>> {
constexpr std::uint64_t operator()(std::basic_string_view<CharT> const& sv) const noexcept {
return wyhash_detail::hash(sv.data(), sizeof(CharT) * sv.size());
std::uint64_t operator()(std::basic_string_view<CharT> const& sv) const noexcept {
return wyhash_detail::hash(sv.data(), static_cast<ssize_t>(sizeof(CharT) * sv.size()));
}
};

template <class T>
struct hash<T*> {
constexpr std::uint64_t operator()(T* ptr) const noexcept {
std::uint64_t operator()(T* ptr) const noexcept {
return wyhash_detail::hash(reinterpret_cast<uintptr_t>(ptr));
}
};
Expand Down

0 comments on commit 49cadff

Please sign in to comment.