[map] Simplify iterators

This commit is contained in:
Behdad Esfahbod 2022-11-17 14:58:50 -07:00
parent 410c14bfa2
commit 238fc14716
1 changed files with 16 additions and 19 deletions

View File

@ -247,8 +247,7 @@ struct hb_hashmap_t
uint32_t hash () const uint32_t hash () const
{ {
uint32_t h = 0; uint32_t h = 0;
for (const auto &item : + hb_array (items, mask ? mask + 1 : 0) for (auto item : iter_items ())
| hb_filter (&item_t::is_real))
h ^= item.total_hash (); h ^= item.total_hash ();
return h; return h;
} }
@ -271,44 +270,42 @@ struct hb_hashmap_t
/* /*
* Iterator * Iterator
*/ */
auto iter () const HB_AUTO_RETURN
auto iter_items () const HB_AUTO_RETURN
( (
+ hb_array (items, mask ? mask + 1 : 0) + hb_array (items, mask ? mask + 1 : 0)
| hb_filter (&item_t::is_real) | hb_filter (&item_t::is_real)
| hb_map (&item_t::get_pair)
) )
auto iter_ref () const HB_AUTO_RETURN auto iter_ref () const HB_AUTO_RETURN
( (
+ hb_array (items, mask ? mask + 1 : 0) + iter_items ()
| hb_filter (&item_t::is_real)
| hb_map (&item_t::get_pair_ref) | hb_map (&item_t::get_pair_ref)
) )
auto keys () const HB_AUTO_RETURN auto iter () const HB_AUTO_RETURN
( (
+ hb_array (items, mask ? mask + 1 : 0) + iter_items ()
| hb_filter (&item_t::is_real) | hb_map (&item_t::get_pair)
| hb_map (&item_t::key)
| hb_map (hb_ridentity)
) )
auto keys_ref () const HB_AUTO_RETURN auto keys_ref () const HB_AUTO_RETURN
( (
+ hb_array (items, mask ? mask + 1 : 0) + iter_items ()
| hb_filter (&item_t::is_real)
| hb_map (&item_t::key) | hb_map (&item_t::key)
) )
auto values () const HB_AUTO_RETURN auto keys () const HB_AUTO_RETURN
( (
+ hb_array (items, mask ? mask + 1 : 0) + keys_ref ()
| hb_filter (&item_t::is_real)
| hb_map (&item_t::value)
| hb_map (hb_ridentity) | hb_map (hb_ridentity)
) )
auto values_ref () const HB_AUTO_RETURN auto values_ref () const HB_AUTO_RETURN
( (
+ hb_array (items, mask ? mask + 1 : 0) + iter_items ()
| hb_filter (&item_t::is_real)
| hb_map (&item_t::value) | hb_map (&item_t::value)
) )
auto values () const HB_AUTO_RETURN
(
+ values_ref ()
| hb_map (hb_ridentity)
)
/* Sink interface. */ /* Sink interface. */
hb_hashmap_t& operator << (const hb_pair_t<K, V>& v) hb_hashmap_t& operator << (const hb_pair_t<K, V>& v)