--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 880F06DE02CD\r
+ for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:27 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.012\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5\r
+ tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id CXOw4NKNK3Hq for <notmuch@notmuchmail.org>;\r
+ Mon, 30 May 2016 04:50:19 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 86A186DE0281\r
+ for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:11 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1b7Lhm-0000On-Uc; Mon, 30 May 2016 07:49:58 -0400\r
+Received: (nullmailer pid 14855 invoked by uid 1000);\r
+ Mon, 30 May 2016 11:50:06 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC2 Patch 4/5] lib: extend private string map API with iterators\r
+Date: Mon, 30 May 2016 08:49:58 -0300\r
+Message-Id: <1464608999-14774-5-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+In-Reply-To: <1464608999-14774-1-git-send-email-david@tethera.net>\r
+References: <1463927339-5441-1-git-send-email-david@tethera.net>\r
+ <1464608999-14774-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 30 May 2016 11:50:27 -0000\r
+\r
+Support for prefix based iterators is perhaps overengineering, but I\r
+wanted to mimic the existing database_config API.\r
+---\r
+ lib/notmuch-private.h | 21 ++++++++++++++-\r
+ lib/string-map.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 2 files changed, 92 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 531b82f..98efdaf 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -539,7 +539,7 @@ _notmuch_string_list_sort (notmuch_string_list_t *list);\r
+ \r
+ /* string-map.c */\r
+ typedef struct _notmuch_string_map notmuch_string_map_t;\r
+-\r
++typedef struct _notmuch_string_map_iterator notmuch_string_map_iterator_t;\r
+ notmuch_string_map_t *\r
+ _notmuch_string_map_create (const void *ctx);\r
+ \r
+@@ -551,6 +551,25 @@ _notmuch_string_map_append (notmuch_string_map_t *map,\r
+ const char *\r
+ _notmuch_string_map_get (notmuch_string_map_t *map, const char *key);\r
+ \r
++notmuch_string_map_iterator_t *\r
++_notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,\r
++ notmuch_bool_t exact);\r
++\r
++notmuch_bool_t\r
++_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iter);\r
++\r
++void\r
++_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iter);\r
++\r
++const char *\r
++_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator);\r
++\r
++const char *\r
++_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);\r
++\r
++void\r
++_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);\r
++\r
+ /* tags.c */\r
+ \r
+ notmuch_tags_t *\r
+diff --git a/lib/string-map.c b/lib/string-map.c\r
+index 0491a10..591ff6d 100644\r
+--- a/lib/string-map.c\r
++++ b/lib/string-map.c\r
+@@ -38,6 +38,12 @@ struct _notmuch_string_map {\r
+ notmuch_string_pair_t *pairs;\r
+ };\r
+ \r
++struct _notmuch_string_map_iterator {\r
++ notmuch_string_pair_t *current;\r
++ notmuch_bool_t exact;\r
++ const char *key;\r
++};\r
++\r
+ notmuch_string_map_t *\r
+ _notmuch_string_map_create (const void *ctx)\r
+ {\r
+@@ -151,3 +157,69 @@ _notmuch_string_map_get (notmuch_string_map_t *map, const char *key)\r
+ \r
+ return pair->value;\r
+ }\r
++\r
++notmuch_string_map_iterator_t *\r
++_notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,\r
++ notmuch_bool_t exact)\r
++{\r
++ notmuch_string_map_iterator_t *iter;\r
++\r
++ _notmuch_string_map_sort (map);\r
++\r
++ iter = talloc (map, notmuch_string_map_iterator_t);\r
++ if (unlikely (iter == NULL))\r
++ return NULL;\r
++\r
++ iter->key = talloc_strdup (iter, key);\r
++ iter->exact = exact;\r
++ iter->current = bsearch_first (map->pairs, map->length, key, exact);\r
++ return iter;\r
++}\r
++\r
++notmuch_bool_t\r
++_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iterator)\r
++{\r
++ if (iterator->current == NULL)\r
++ return FALSE;\r
++\r
++ /* sentinel */\r
++ if (iterator->current->key == NULL)\r
++ return FALSE;\r
++\r
++ return (0 == string_cmp (iterator->key, iterator->current->key, iterator->exact));\r
++\r
++}\r
++\r
++void\r
++_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iterator)\r
++{\r
++\r
++ if (! _notmuch_string_map_iterator_valid (iterator))\r
++ return;\r
++\r
++ (iterator->current)++;\r
++}\r
++\r
++const char *\r
++_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator)\r
++{\r
++ if (! _notmuch_string_map_iterator_valid (iterator))\r
++ return NULL;\r
++\r
++ return iterator->current->key;\r
++}\r
++\r
++const char *\r
++_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator)\r
++{\r
++ if (! _notmuch_string_map_iterator_valid (iterator))\r
++ return NULL;\r
++\r
++ return iterator->current->value;\r
++}\r
++\r
++void\r
++_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator)\r
++{\r
++ talloc_free (iterator);\r
++}\r
+-- \r
+2.8.1\r
+\r