--- /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 82FA26DE0939\r
+ for <notmuch@notmuchmail.org>; Sun, 12 Jun 2016 18:06:41 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.011\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.011 tagged_above=-999 required=5\r
+ tests=[AWL=-0.000, 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 gb8S3PMOFKjp for <notmuch@notmuchmail.org>;\r
+ Sun, 12 Jun 2016 18:06:33 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id A0FD26DE02DA\r
+ for <notmuch@notmuchmail.org>; Sun, 12 Jun 2016 18:06:13 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1bCGKF-0003xh-FN; Sun, 12 Jun 2016 21:05:59 -0400\r
+Received: (nullmailer pid 5672 invoked by uid 1000);\r
+ Mon, 13 Jun 2016 01:06:04 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/8] lib: extend private string map API with iterators\r
+Date: Sun, 12 Jun 2016 22:05:51 -0300\r
+Message-Id: <1465779955-5539-5-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+In-Reply-To: <1465779955-5539-1-git-send-email-david@tethera.net>\r
+References: <1465779955-5539-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, 13 Jun 2016 01:06:41 -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 5abde88..65f7ead 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