[map] Remove invalid-key special-casing
Can override invalid-key value now.
This commit is contained in:
parent
5328b73fba
commit
3f6a8f69a0
|
@ -84,7 +84,6 @@ struct hb_hashmap_t
|
||||||
void clear ()
|
void clear ()
|
||||||
{
|
{
|
||||||
new (std::addressof (key)) K ();
|
new (std::addressof (key)) K ();
|
||||||
key = hb_coerce<K> (kINVALID);
|
|
||||||
new (std::addressof (value)) V ();
|
new (std::addressof (value)) V ();
|
||||||
value = hb_coerce<V> (vINVALID);
|
value = hb_coerce<V> (vINVALID);
|
||||||
hash = 0;
|
hash = 0;
|
||||||
|
@ -295,8 +294,6 @@ struct hb_hashmap_t
|
||||||
bool set_with_hash (K key, uint32_t hash, VV&& value, bool is_delete=false)
|
bool set_with_hash (K key, uint32_t hash, VV&& value, bool is_delete=false)
|
||||||
{
|
{
|
||||||
if (unlikely (!successful)) return false;
|
if (unlikely (!successful)) return false;
|
||||||
const K kinv = hb_coerce<K> (kINVALID);
|
|
||||||
if (unlikely (key == kinv)) return true;
|
|
||||||
if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false;
|
if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false;
|
||||||
unsigned int i = bucket_for_hash (key, hash);
|
unsigned int i = bucket_for_hash (key, hash);
|
||||||
|
|
||||||
|
|
|
@ -168,9 +168,8 @@ main (int argc, char **argv)
|
||||||
m1.set (hb_map_t {pair (1u, 2u)}, hb_map_t {pair (2u, 3u)});
|
m1.set (hb_map_t {pair (1u, 2u)}, hb_map_t {pair (2u, 3u)});
|
||||||
m2.set (hb_map_t {pair (1u, 2u)}, hb_map_t {pair (2u, 3u)});
|
m2.set (hb_map_t {pair (1u, 2u)}, hb_map_t {pair (2u, 3u)});
|
||||||
|
|
||||||
/* Cannot override empty map. */
|
assert (m1.get (hb_map_t ()) == hb_map_t {pair (1u, 2u)});
|
||||||
assert (m1.get (hb_map_t ()) == hb_map_t ());
|
assert (m2.get (hb_map_t ()) == hb_map_t {pair (1u, 2u)});
|
||||||
assert (m2.get (hb_map_t ()) == hb_map_t ());
|
|
||||||
|
|
||||||
assert (m1.get (hb_map_t {pair (1u, 2u)}) == hb_map_t {pair (2u, 3u)});
|
assert (m1.get (hb_map_t {pair (1u, 2u)}) == hb_map_t {pair (2u, 3u)});
|
||||||
assert (m2.get (hb_map_t {pair (1u, 2u)}) == hb_map_t {pair (2u, 3u)});
|
assert (m2.get (hb_map_t {pair (1u, 2u)}) == hb_map_t {pair (2u, 3u)});
|
||||||
|
@ -190,9 +189,8 @@ main (int argc, char **argv)
|
||||||
m1.set (hb_set_t {1, 1000}, hb_set_t {2});
|
m1.set (hb_set_t {1, 1000}, hb_set_t {2});
|
||||||
m2.set (hb_set_t {1, 1000}, hb_set_t {2});
|
m2.set (hb_set_t {1, 1000}, hb_set_t {2});
|
||||||
|
|
||||||
/* Cannot override empty set. */
|
assert (m1.get (hb_set_t ()) == hb_set_t {1});
|
||||||
assert (m1.get (hb_set_t ()) == hb_set_t ());
|
assert (m2.get (hb_set_t ()) == hb_set_t {1});
|
||||||
assert (m2.get (hb_set_t ()) == hb_set_t ());
|
|
||||||
|
|
||||||
assert (m1.get (hb_set_t {1000, 1}) == hb_set_t {2});
|
assert (m1.get (hb_set_t {1000, 1}) == hb_set_t {2});
|
||||||
assert (m2.get (hb_set_t {1000, 1}) == hb_set_t {2});
|
assert (m2.get (hb_set_t {1000, 1}) == hb_set_t {2});
|
||||||
|
@ -214,9 +212,8 @@ main (int argc, char **argv)
|
||||||
m1.set (vector_t {1}, vector_t {2});
|
m1.set (vector_t {1}, vector_t {2});
|
||||||
m2.set (vector_t {1}, vector_t {2});
|
m2.set (vector_t {1}, vector_t {2});
|
||||||
|
|
||||||
/* Cannot override empty vector. */
|
assert (m1.get (vector_t ()) == vector_t {1});
|
||||||
assert (m1.get (vector_t ()) == vector_t ());
|
assert (m2.get (vector_t ()) == vector_t {1});
|
||||||
assert (m2.get (vector_t ()) == vector_t ());
|
|
||||||
|
|
||||||
assert (m1.get (vector_t {1}) == vector_t {2});
|
assert (m1.get (vector_t {1}) == vector_t {2});
|
||||||
assert (m2.get (vector_t {1}) == vector_t {2});
|
assert (m2.get (vector_t {1}) == vector_t {2});
|
||||||
|
|
Loading…
Reference in New Issue