[cache] Residual

This commit is contained in:
Behdad Esfahbod 2022-08-03 13:02:18 -06:00
parent ec90d1e161
commit b78546b1d2
1 changed files with 5 additions and 5 deletions

View File

@ -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);