[map] Deref pointers before equality check
This commit is contained in:
parent
c98f51da71
commit
ef33b5d1f6
|
@ -51,6 +51,8 @@ struct hb_hashmap_t
|
||||||
K key;
|
K key;
|
||||||
V value;
|
V value;
|
||||||
|
|
||||||
|
bool operator== (K o) { return hb_deref_pointer (key) == hb_deref_pointer (o); }
|
||||||
|
bool operator== (const item_t &o) { return *this == o.key; }
|
||||||
bool is_unused () const { return key == kINVALID; }
|
bool is_unused () const { return key == kINVALID; }
|
||||||
bool is_tombstone () const { return key != kINVALID && value == vINVALID; }
|
bool is_tombstone () const { return key != kINVALID && value == vINVALID; }
|
||||||
};
|
};
|
||||||
|
@ -153,7 +155,7 @@ struct hb_hashmap_t
|
||||||
{
|
{
|
||||||
if (unlikely (!items)) return vINVALID;
|
if (unlikely (!items)) return vINVALID;
|
||||||
unsigned int i = bucket_for (key);
|
unsigned int i = bucket_for (key);
|
||||||
return items[i].key == key ? items[i].value : vINVALID;
|
return items[i] == key ? items[i].value : vINVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void del (K key) { set (key, vINVALID); }
|
void del (K key) { set (key, vINVALID); }
|
||||||
|
@ -185,7 +187,7 @@ struct hb_hashmap_t
|
||||||
unsigned int tombstone = (unsigned) -1;
|
unsigned int tombstone = (unsigned) -1;
|
||||||
while (!items[i].is_unused ())
|
while (!items[i].is_unused ())
|
||||||
{
|
{
|
||||||
if (items[i].key == key)
|
if (items[i] == key)
|
||||||
return i;
|
return i;
|
||||||
if (tombstone == (unsigned) -1 && items[i].is_tombstone ())
|
if (tombstone == (unsigned) -1 && items[i].is_tombstone ())
|
||||||
tombstone = i;
|
tombstone = i;
|
||||||
|
|
|
@ -66,9 +66,9 @@ template <typename T> struct hb_match_pointer<T *> { typedef T type; enum { valu
|
||||||
static const struct
|
static const struct
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T& operator () (T v) { return v; }
|
T operator () (T v) const { return v; }
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T& operator () (T *v) { return *v; }
|
T& operator () (T *v) const { return *v; }
|
||||||
} hb_deref_pointer HB_UNUSED;
|
} hb_deref_pointer HB_UNUSED;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue