[map] add iteration
authorrsheeter <rsheeter@google.com>
Wed, 8 May 2019 18:40:31 +0000 (11:40 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 8 May 2019 22:08:33 +0000 (15:08 -0700)
src/hb-map.hh

index 13099af..2b25c2e 100644 (file)
@@ -62,6 +62,7 @@ struct hb_hashmap_t
     bool is_unused () const    { return key == kINVALID; }
     bool is_tombstone () const { return key != kINVALID && value == vINVALID; }
     bool is_real () const { return key != kINVALID && value != vINVALID; }
+    hb_pair_t<K, V> get_pair() const { return hb_pair (key, value); }
   };
 
   hb_object_header_t header;
@@ -206,6 +207,16 @@ struct hb_hashmap_t
 
   unsigned int get_population () const { return population; }
 
+  /*
+   * Iterator
+   */
+  auto iter() const HB_AUTO_RETURN
+  (
+    + hb_array_t<item_t> (items, mask + 1)
+    | hb_filter (&item_t::is_real)
+    | hb_map (&item_t::get_pair)
+  )
+
   protected:
 
   unsigned int bucket_for (K key) const