[geary/wip/713891-traversable: 10/12] Add to_hash_map



commit ddad67140b05e7e2afe26a62b296a663f6bc9d2c
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Dec 11 18:36:43 2013 -0800

    Add to_hash_map

 src/engine/util/util-iterable.vala |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/src/engine/util/util-iterable.vala b/src/engine/util/util-iterable.vala
index 2effe7a..52343e7 100644
--- a/src/engine/util/util-iterable.vala
+++ b/src/engine/util/util-iterable.vala
@@ -127,4 +127,21 @@ public class Geary.Iterable<G> : BaseObject {
         add_all_to(c);
         return c;
     }
+    
+    public Gee.Map<K, G> add_all_to_map<K>(Gee.Map<K, G> c, Gee.MapFunc<K, G> key_func) {
+        while (i.next()) {
+            G g = i  get();
+            c  set(key_func(g), g);
+        }
+        return c;
+    }
+    
+    public Gee.HashMap<K, G> to_hash_map<K>(Gee.MapFunc<K, G> key_func,
+        owned Gee.HashDataFunc<K>? key_hash_func = null,
+        owned Gee.EqualDataFunc<K>? key_equal_func = null,
+        owned Gee.EqualDataFunc<G>? value_equal_func = null) {
+        Gee.HashMap<K, G> c = new Gee.HashMap<K, G>(key_hash_func, key_equal_func, value_equal_func);
+        add_all_to_map<K>(c, key_func);
+        return c;
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]