3 #ifndef _CUCKOOHASH_UTIL_HH
4 #define _CUCKOOHASH_UTIL_HH
15 #define LIBCUCKOO_DBG(fmt, ...) \
18 fprintf(stderr, "\x1b[32m" \
19 "[libcuckoo:%s:%d:%lu] " fmt "" \
22 std::hash<std::thread::id>()(std::this_thread::get_id()), \
25 #define LIBCUCKOO_DBG(fmt, ...) \
36 #define LIBCUCKOO_ALIGNAS(x) __attribute__((aligned(x)))
38 #define LIBCUCKOO_ALIGNAS(x) alignas(x)
46 #define LIBCUCKOO_SQUELCH_PADDING_WARNING __pragma(warning(suppress : 4324))
48 #define LIBCUCKOO_SQUELCH_PADDING_WARNING
57 #define LIBCUCKOO_SQUELCH_DEADCODE_WARNING_BEGIN \
59 __pragma(warning(push)); \
60 __pragma(warning(disable : 4702)) \
62 #define LIBCUCKOO_SQUELCH_DEADCODE_WARNING_END __pragma(warning(pop))
64 #define LIBCUCKOO_SQUELCH_DEADCODE_WARNING_BEGIN
65 #define LIBCUCKOO_SQUELCH_DEADCODE_WARNING_END
87 virtual const char *
what() const noexcept
override {
88 return "Automatic expansion triggered when load factor was below "
98 const double load_factor_;
118 virtual const char *
what() const noexcept
override {
119 return "Expansion beyond maximum hashpower";
125 size_t hashpower() const noexcept {
return hashpower_; }
128 const size_t hashpower_;
150 template <
typename F,
typename MappedType>
153 template <
typename InnerF,
154 typename = decltype(std::declval<InnerF>()(
155 std::declval<MappedType&>(), std::declval<UpsertContext>()))>
156 static std::true_type test(
int);
161 template <
typename InnerF>
162 static std::false_type test(
float);
165 using type = decltype(test<F>(0));
168 template <
typename F,
typename MappedType>
169 bool InvokeUpraseFn(F& f, MappedType& mapped,
UpsertContext context,
171 return f(mapped, context);
174 template <
typename F,
typename MappedType>
175 bool InvokeUpraseFn(F& f, MappedType& mapped,
UpsertContext context,
177 if (context == UpsertContext::ALREADY_EXISTED) {
187 template <
typename F,
typename MappedType,
bool kCanInvokeWithUpsertContext>
190 template <
typename F,
typename MappedType>
194 bool operator()(MappedType& mapped,
UpsertContext context)
const {
200 template <
typename F,
typename MappedType>
204 bool operator()(MappedType& mapped) {
214 #endif // _CUCKOOHASH_UTIL_HH