[map] Take const key

This commit is contained in:
Behdad Esfahbod 2022-11-21 20:46:01 -07:00
parent 3d1c76f713
commit cf20d2ec5d
3 changed files with 9 additions and 9 deletions

View File

@ -199,7 +199,7 @@ struct hb_hashmap_t
} }
template <typename VV> template <typename VV>
bool set_with_hash (K key, uint32_t hash, VV&& value, bool is_delete=false) bool set_with_hash (const K &key, uint32_t hash, VV&& value, bool is_delete=false)
{ {
if (unlikely (!successful)) return false; if (unlikely (!successful)) return false;
if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false; if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false;
@ -229,21 +229,21 @@ struct hb_hashmap_t
} }
template <typename VV> template <typename VV>
bool set (K key, VV&& value) { return set_with_hash (key, hb_hash (key), std::forward<VV> (value)); } bool set (const K &key, VV&& value) { return set_with_hash (key, hb_hash (key), std::forward<VV> (value)); }
const V& get_with_hash (K key, uint32_t hash) const const V& get_with_hash (const K &key, uint32_t hash) const
{ {
if (unlikely (!items)) return item_t::default_value (); if (unlikely (!items)) return item_t::default_value ();
auto &item = item_for_hash (key, hash); auto &item = item_for_hash (key, hash);
return item.is_real () && item == key ? item.value : item_t::default_value (); return item.is_real () && item == key ? item.value : item_t::default_value ();
} }
const V& get (K key) const const V& get (const K &key) const
{ {
if (unlikely (!items)) return item_t::default_value (); if (unlikely (!items)) return item_t::default_value ();
return get_with_hash (key, hb_hash (key)); return get_with_hash (key, hb_hash (key));
} }
void del (K key) { set_with_hash (key, hb_hash (key), item_t::default_value (), true); } void del (const K &key) { set_with_hash (key, hb_hash (key), item_t::default_value (), true); }
/* Has interface. */ /* Has interface. */
typedef const V& value_t; typedef const V& value_t;

View File

@ -216,15 +216,15 @@ struct hb_subset_plan_t
{ {
if (sanitized_table_cache if (sanitized_table_cache
&& !sanitized_table_cache->in_error () && !sanitized_table_cache->in_error ()
&& sanitized_table_cache->has (T::tableTag)) { && sanitized_table_cache->has (0+T::tableTag)) {
return hb_blob_reference (sanitized_table_cache->get (T::tableTag).get ()); return hb_blob_reference (sanitized_table_cache->get (0+T::tableTag).get ());
} }
hb::unique_ptr<hb_blob_t> table_blob {hb_sanitize_context_t ().reference_table<T> (source)}; hb::unique_ptr<hb_blob_t> table_blob {hb_sanitize_context_t ().reference_table<T> (source)};
hb_blob_t* ret = hb_blob_reference (table_blob.get ()); hb_blob_t* ret = hb_blob_reference (table_blob.get ());
if (likely (sanitized_table_cache)) if (likely (sanitized_table_cache))
sanitized_table_cache->set (T::tableTag, sanitized_table_cache->set (0+T::tableTag,
std::move (table_blob)); std::move (table_blob));
return ret; return ret;

View File

@ -232,7 +232,7 @@ main (int argc, char **argv)
// See commit f657ef7e57c889309c2d9d37934368ca255f9d5b and its revert. // See commit f657ef7e57c889309c2d9d37934368ca255f9d5b and its revert.
//m.set (hb::unique_ptr<hb_set_t> (hb_set_get_empty ()), //m.set (hb::unique_ptr<hb_set_t> (hb_set_get_empty ()),
// hb::unique_ptr<hb_set_t> (hb_set_get_empty ())); // hb::unique_ptr<hb_set_t> (hb_set_get_empty ()));
//m.get (hb::unique_ptr<hb_set_t> (hb_set_get_empty ())); m.get (hb::unique_ptr<hb_set_t> (hb_set_get_empty ()));
m.iter_ref (); m.iter_ref ();
m.keys_ref (); m.keys_ref ();
m.values_ref (); m.values_ref ();