[hashmap] Add keys_ref() and values_ref()

This commit is contained in:
Behdad Esfahbod 2022-07-12 13:19:31 -06:00
parent cddcb31065
commit d8f9d51780
2 changed files with 19 additions and 0 deletions

View File

@ -301,6 +301,12 @@ struct hb_hashmap_t
| hb_map (&item_t::key)
| hb_map (hb_ridentity)
)
auto keys_ref () const HB_AUTO_RETURN
(
+ hb_array (items, mask ? mask + 1 : 0)
| hb_filter (&item_t::is_real)
| hb_map (&item_t::key)
)
auto values () const HB_AUTO_RETURN
(
+ hb_array (items, mask ? mask + 1 : 0)
@ -308,6 +314,12 @@ struct hb_hashmap_t
| hb_map (&item_t::value)
| hb_map (hb_ridentity)
)
auto values_ref () const HB_AUTO_RETURN
(
+ hb_array (items, mask ? mask + 1 : 0)
| hb_filter (&item_t::is_real)
| hb_map (&item_t::value)
)
/* Sink interface. */
hb_hashmap_t& operator << (const hb_pair_t<K, V>& v)

View File

@ -195,6 +195,11 @@ main (int argc, char **argv)
m.get (hb::shared_ptr<hb_set_t> ());
m.get (hb::shared_ptr<hb_set_t> (hb_set_get_empty ()));
m.iter ();
m.keys ();
m.values ();
m.iter_ref ();
m.keys_ref ();
m.values_ref ();
}
/* Test hb::unique_ptr. */
hb_hash (hb::unique_ptr<hb_set_t> ());
@ -204,6 +209,8 @@ main (int argc, char **argv)
m.get (hb::unique_ptr<hb_set_t> ());
m.get (hb::unique_ptr<hb_set_t> (hb_set_get_empty ()));
m.iter_ref ();
m.keys_ref ();
m.values_ref ();
}
return 0;