1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id 880F06DE02CD
\r
6 for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:27 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id CXOw4NKNK3Hq for <notmuch@notmuchmail.org>;
\r
17 Mon, 30 May 2016 04:50:19 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id 86A186DE0281
\r
20 for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:11 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1b7Lhm-0000On-Uc; Mon, 30 May 2016 07:49:58 -0400
\r
24 Received: (nullmailer pid 14855 invoked by uid 1000);
\r
25 Mon, 30 May 2016 11:50:06 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [RFC2 Patch 4/5] lib: extend private string map API with iterators
\r
29 Date: Mon, 30 May 2016 08:49:58 -0300
\r
30 Message-Id: <1464608999-14774-5-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.8.1
\r
32 In-Reply-To: <1464608999-14774-1-git-send-email-david@tethera.net>
\r
33 References: <1463927339-5441-1-git-send-email-david@tethera.net>
\r
34 <1464608999-14774-1-git-send-email-david@tethera.net>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.20
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Mon, 30 May 2016 11:50:27 -0000
\r
49 Support for prefix based iterators is perhaps overengineering, but I
\r
50 wanted to mimic the existing database_config API.
\r
52 lib/notmuch-private.h | 21 ++++++++++++++-
\r
53 lib/string-map.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
\r
54 2 files changed, 92 insertions(+), 1 deletion(-)
\r
56 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
57 index 531b82f..98efdaf 100644
\r
58 --- a/lib/notmuch-private.h
\r
59 +++ b/lib/notmuch-private.h
\r
60 @@ -539,7 +539,7 @@ _notmuch_string_list_sort (notmuch_string_list_t *list);
\r
63 typedef struct _notmuch_string_map notmuch_string_map_t;
\r
65 +typedef struct _notmuch_string_map_iterator notmuch_string_map_iterator_t;
\r
66 notmuch_string_map_t *
\r
67 _notmuch_string_map_create (const void *ctx);
\r
69 @@ -551,6 +551,25 @@ _notmuch_string_map_append (notmuch_string_map_t *map,
\r
71 _notmuch_string_map_get (notmuch_string_map_t *map, const char *key);
\r
73 +notmuch_string_map_iterator_t *
\r
74 +_notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,
\r
75 + notmuch_bool_t exact);
\r
78 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iter);
\r
81 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iter);
\r
84 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator);
\r
87 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);
\r
90 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);
\r
95 diff --git a/lib/string-map.c b/lib/string-map.c
\r
96 index 0491a10..591ff6d 100644
\r
97 --- a/lib/string-map.c
\r
98 +++ b/lib/string-map.c
\r
99 @@ -38,6 +38,12 @@ struct _notmuch_string_map {
\r
100 notmuch_string_pair_t *pairs;
\r
103 +struct _notmuch_string_map_iterator {
\r
104 + notmuch_string_pair_t *current;
\r
105 + notmuch_bool_t exact;
\r
109 notmuch_string_map_t *
\r
110 _notmuch_string_map_create (const void *ctx)
\r
112 @@ -151,3 +157,69 @@ _notmuch_string_map_get (notmuch_string_map_t *map, const char *key)
\r
114 return pair->value;
\r
117 +notmuch_string_map_iterator_t *
\r
118 +_notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,
\r
119 + notmuch_bool_t exact)
\r
121 + notmuch_string_map_iterator_t *iter;
\r
123 + _notmuch_string_map_sort (map);
\r
125 + iter = talloc (map, notmuch_string_map_iterator_t);
\r
126 + if (unlikely (iter == NULL))
\r
129 + iter->key = talloc_strdup (iter, key);
\r
130 + iter->exact = exact;
\r
131 + iter->current = bsearch_first (map->pairs, map->length, key, exact);
\r
136 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iterator)
\r
138 + if (iterator->current == NULL)
\r
142 + if (iterator->current->key == NULL)
\r
145 + return (0 == string_cmp (iterator->key, iterator->current->key, iterator->exact));
\r
150 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iterator)
\r
153 + if (! _notmuch_string_map_iterator_valid (iterator))
\r
156 + (iterator->current)++;
\r
160 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator)
\r
162 + if (! _notmuch_string_map_iterator_valid (iterator))
\r
165 + return iterator->current->key;
\r
169 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator)
\r
171 + if (! _notmuch_string_map_iterator_valid (iterator))
\r
174 + return iterator->current->value;
\r
178 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator)
\r
180 + talloc_free (iterator);
\r