Skip to content

Commit

Permalink
GCC support
Browse files Browse the repository at this point in the history
  • Loading branch information
Daskie committed Mar 10, 2023
1 parent e0a8c56 commit 0ee8b3d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ qc_setup_target(qc-hash INTERFACE_LIBRARY)

add_subdirectory(test)

add_subdirectory(benchmark EXCLUDE_FROM_ALL)
# TEMPORARILY OUT OF COMMISSION
# WILL SWITCH TO GOOGLE BENCHMARK SOON
#add_subdirectory(benchmark EXCLUDE_FROM_ALL)

qc_setup_install(TARGETS qc-hash)
5 changes: 5 additions & 0 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
///
/// TEMPORARILY OUT OF COMMISSION
/// WILL SWITCH TO GOOGLE BENCHMARK SOON
///

#include <array>
#include <chrono>
#include <filesystem>
Expand Down
15 changes: 9 additions & 6 deletions qc-hash.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

///
/// QC Hash 3.0.2
/// QC Hash 3.0.3
///
/// https://github.com/daskie/qc-hash
///
Expand Down Expand Up @@ -250,6 +250,9 @@ namespace qc::hash
///
template <typename KOther, typename K> concept Compatible = Rawable<K> && Rawable<KOther> && IsCompatible<K, KOther>::value;

// Used for testing
struct _RawFriend;

///
/// An associative container that stores unique-key key-pair values. Uses a flat memory model, linear probing, and a
/// whole lot of optimizations that make this an extremely fast map for small elements
Expand Down Expand Up @@ -296,8 +299,7 @@ namespace qc::hash
// Internal iterator class forward declaration. Prefer `iterator` and `const_iterator`
template <bool constant> class _Iterator;

// Friend class used for testing
friend struct _RawFriend;
friend ::qc::hash::_RawFriend;

public:

Expand Down Expand Up @@ -749,9 +751,10 @@ namespace qc::hash

template <bool move> void _forwardData(std::conditional_t<move, RawMap, const RawMap> & other);

template <bool insertionForm> struct _FindKeyResult;
template <> struct _FindKeyResult<false> { E * element; bool isPresent; };
template <> struct _FindKeyResult<true> { E * element; bool isPresent; bool isSpecial; unsigned char specialI; };

struct _FindKeyResult1 { E * element; bool isPresent; };
struct _FindKeyResult2 { E * element; bool isPresent; bool isSpecial; unsigned char specialI; };
template <bool insertionForm> using _FindKeyResult = std::conditional_t<insertionForm, _FindKeyResult2, _FindKeyResult1>;

// If the key is not present, returns the slot after the the key's bucket
template <bool insertionForm, Compatible<K> K_> _FindKeyResult<insertionForm> _findKey(const K_ & key) const;
Expand Down
16 changes: 7 additions & 9 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// First include in order to test its own includes
#include <qc-hash.hpp>

#include <cmath>

#include <array>
#include <chrono>
#include <map>
Expand Down Expand Up @@ -298,10 +300,8 @@ TEST(identityHash, enums)
testEnumHash<EnumS16>();
testEnumHash<EnumU32>();
testEnumHash<EnumS32>();
#ifdef _WIN64
testEnumHash<EnumU64>();
testEnumHash<EnumS64>();
#endif
}

template <typename T>
Expand Down Expand Up @@ -1446,16 +1446,18 @@ TEST(set, stats)
{
constexpr u64 size{8192u};

qc::Random random{};

RawSet<int> s(size);
for (int i{0}; i < size; ++i)
{
s.insert(rand());
s.insert(random.next<int>());
}

const SetDistStats stats{calcStats(s)};
ASSERT_EQ(0u, stats.median);
ASSERT_NEAR(0.2, stats.mean, 0.1);
ASSERT_NEAR(0.65, stats.stdDev, 0.1);
ASSERT_NEAR(0.5, stats.mean, 0.1);
ASSERT_NEAR(1.25, stats.stdDev, 0.25);
}

template <typename K, typename V> void testStaticMemory()
Expand Down Expand Up @@ -1956,7 +1958,6 @@ TEST(heterogeneity, general)
static_assert(!HeterogeneityCompiles<u32, s64>);
static_assert(!HeterogeneityCompiles<u32, bool>);

#ifdef _WIN64
static_assert(HeterogeneityCompiles<u64, u8>);
static_assert(HeterogeneityCompiles<u64, u16>);
static_assert(HeterogeneityCompiles<u64, u32>);
Expand All @@ -1966,7 +1967,6 @@ TEST(heterogeneity, general)
static_assert(!HeterogeneityCompiles<u64, s32>);
static_assert(!HeterogeneityCompiles<u64, s64>);
static_assert(!HeterogeneityCompiles<u64, bool>);
#endif

static_assert(HeterogeneityCompiles<s8, s8>);
static_assert(!HeterogeneityCompiles<s8, s16>);
Expand Down Expand Up @@ -1998,7 +1998,6 @@ TEST(heterogeneity, general)
static_assert(!HeterogeneityCompiles<s32, u64>);
static_assert(!HeterogeneityCompiles<s32, bool>);

#ifdef _WIN64
static_assert(HeterogeneityCompiles<s64, s8>);
static_assert(HeterogeneityCompiles<s64, s16>);
static_assert(HeterogeneityCompiles<s64, s32>);
Expand All @@ -2008,7 +2007,6 @@ TEST(heterogeneity, general)
static_assert(HeterogeneityCompiles<s64, u32>);
static_assert(!HeterogeneityCompiles<s64, u64>);
static_assert(!HeterogeneityCompiles<s64, bool>);
#endif

static_assert(HeterogeneityCompiles<int *, int *>);
static_assert(HeterogeneityCompiles<int *, const int *>);
Expand Down

0 comments on commit 0ee8b3d

Please sign in to comment.