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 82FA26DE0939
\r
6 for <notmuch@notmuchmail.org>; Sun, 12 Jun 2016 18:06:41 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.011 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.000, 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 gb8S3PMOFKjp for <notmuch@notmuchmail.org>;
\r
17 Sun, 12 Jun 2016 18:06:33 -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 A0FD26DE02DA
\r
20 for <notmuch@notmuchmail.org>; Sun, 12 Jun 2016 18:06:13 -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 1bCGKF-0003xh-FN; Sun, 12 Jun 2016 21:05:59 -0400
\r
24 Received: (nullmailer pid 5672 invoked by uid 1000);
\r
25 Mon, 13 Jun 2016 01:06:04 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH 4/8] lib: extend private string map API with iterators
\r
29 Date: Sun, 12 Jun 2016 22:05:51 -0300
\r
30 Message-Id: <1465779955-5539-5-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.8.1
\r
32 In-Reply-To: <1465779955-5539-1-git-send-email-david@tethera.net>
\r
33 References: <1465779955-5539-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Mon, 13 Jun 2016 01:06:41 -0000
\r
48 Support for prefix based iterators is perhaps overengineering, but I
\r
49 wanted to mimic the existing database_config API.
\r
51 lib/notmuch-private.h | 21 ++++++++++++++-
\r
52 lib/string-map.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
\r
53 2 files changed, 92 insertions(+), 1 deletion(-)
\r
55 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
56 index 5abde88..65f7ead 100644
\r
57 --- a/lib/notmuch-private.h
\r
58 +++ b/lib/notmuch-private.h
\r
59 @@ -539,7 +539,7 @@ _notmuch_string_list_sort (notmuch_string_list_t *list);
\r
62 typedef struct _notmuch_string_map notmuch_string_map_t;
\r
64 +typedef struct _notmuch_string_map_iterator notmuch_string_map_iterator_t;
\r
65 notmuch_string_map_t *
\r
66 _notmuch_string_map_create (const void *ctx);
\r
68 @@ -551,6 +551,25 @@ _notmuch_string_map_append (notmuch_string_map_t *map,
\r
70 _notmuch_string_map_get (notmuch_string_map_t *map, const char *key);
\r
72 +notmuch_string_map_iterator_t *
\r
73 +_notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,
\r
74 + notmuch_bool_t exact);
\r
77 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iter);
\r
80 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iter);
\r
83 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator);
\r
86 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);
\r
89 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);
\r
94 diff --git a/lib/string-map.c b/lib/string-map.c
\r
95 index 0491a10..591ff6d 100644
\r
96 --- a/lib/string-map.c
\r
97 +++ b/lib/string-map.c
\r
98 @@ -38,6 +38,12 @@ struct _notmuch_string_map {
\r
99 notmuch_string_pair_t *pairs;
\r
102 +struct _notmuch_string_map_iterator {
\r
103 + notmuch_string_pair_t *current;
\r
104 + notmuch_bool_t exact;
\r
108 notmuch_string_map_t *
\r
109 _notmuch_string_map_create (const void *ctx)
\r
111 @@ -151,3 +157,69 @@ _notmuch_string_map_get (notmuch_string_map_t *map, const char *key)
\r
113 return pair->value;
\r
116 +notmuch_string_map_iterator_t *
\r
117 +_notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,
\r
118 + notmuch_bool_t exact)
\r
120 + notmuch_string_map_iterator_t *iter;
\r
122 + _notmuch_string_map_sort (map);
\r
124 + iter = talloc (map, notmuch_string_map_iterator_t);
\r
125 + if (unlikely (iter == NULL))
\r
128 + iter->key = talloc_strdup (iter, key);
\r
129 + iter->exact = exact;
\r
130 + iter->current = bsearch_first (map->pairs, map->length, key, exact);
\r
135 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iterator)
\r
137 + if (iterator->current == NULL)
\r
141 + if (iterator->current->key == NULL)
\r
144 + return (0 == string_cmp (iterator->key, iterator->current->key, iterator->exact));
\r
149 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iterator)
\r
152 + if (! _notmuch_string_map_iterator_valid (iterator))
\r
155 + (iterator->current)++;
\r
159 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator)
\r
161 + if (! _notmuch_string_map_iterator_valid (iterator))
\r
164 + return iterator->current->key;
\r
168 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator)
\r
170 + if (! _notmuch_string_map_iterator_valid (iterator))
\r
173 + return iterator->current->value;
\r
177 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator)
\r
179 + talloc_free (iterator);
\r