|
|
|
@ -38,12 +38,12 @@ template <unsigned int key_bits=16, |
|
|
|
|
bool thread_safe=true> |
|
|
|
|
struct hb_cache_t |
|
|
|
|
{ |
|
|
|
|
static_assert ((key_bits >= cache_bits), ""); |
|
|
|
|
static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (hb_atomic_int_t)), ""); |
|
|
|
|
static_assert (sizeof (hb_atomic_int_t) == sizeof (unsigned int), ""); |
|
|
|
|
|
|
|
|
|
using item_t = typename std::conditional<thread_safe, hb_atomic_int_t, int>::type; |
|
|
|
|
|
|
|
|
|
static_assert ((key_bits >= cache_bits), ""); |
|
|
|
|
static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (item_t)), ""); |
|
|
|
|
static_assert (sizeof (item_t) == sizeof (unsigned int), ""); |
|
|
|
|
|
|
|
|
|
void init () { clear (); } |
|
|
|
|
void fini () {} |
|
|
|
|
|
|
|
|
@ -57,7 +57,7 @@ struct hb_cache_t |
|
|
|
|
{ |
|
|
|
|
unsigned int k = key & ((1u<<cache_bits)-1); |
|
|
|
|
unsigned int v = values[k]; |
|
|
|
|
if ((key_bits + value_bits - cache_bits == 8 * sizeof (hb_atomic_int_t) && v == (unsigned int) -1) || |
|
|
|
|
if ((key_bits + value_bits - cache_bits == 8 * sizeof (item_t) && v == (unsigned int) -1) || |
|
|
|
|
(v >> value_bits) != (key >> cache_bits)) |
|
|
|
|
return false; |
|
|
|
|
*value = v & ((1u<<value_bits)-1); |
|
|
|
|