Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 36 / 8bcb7b67de412ce6fc0a0efb847a1b121b3525
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.012\r
10 X-Spam-Level: \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
13  autolearn=disabled\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
37 Precedence: list\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
48 \r
49 Support for prefix based iterators is perhaps overengineering, but I\r
50 wanted to mimic the existing database_config API.\r
51 ---\r
52  lib/notmuch-private.h | 21 ++++++++++++++-\r
53  lib/string-map.c      | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
54  2 files changed, 92 insertions(+), 1 deletion(-)\r
55 \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
61  \r
62  /* string-map.c */\r
63  typedef struct _notmuch_string_map  notmuch_string_map_t;\r
64 -\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
68  \r
69 @@ -551,6 +551,25 @@ _notmuch_string_map_append (notmuch_string_map_t *map,\r
70  const char *\r
71  _notmuch_string_map_get (notmuch_string_map_t *map, const char *key);\r
72  \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
76 +\r
77 +notmuch_bool_t\r
78 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iter);\r
79 +\r
80 +void\r
81 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iter);\r
82 +\r
83 +const char *\r
84 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator);\r
85 +\r
86 +const char *\r
87 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);\r
88 +\r
89 +void\r
90 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);\r
91 +\r
92  /* tags.c */\r
93  \r
94  notmuch_tags_t *\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
101  };\r
102  \r
103 +struct _notmuch_string_map_iterator {\r
104 +    notmuch_string_pair_t *current;\r
105 +    notmuch_bool_t exact;\r
106 +    const char *key;\r
107 +};\r
108 +\r
109  notmuch_string_map_t *\r
110  _notmuch_string_map_create (const void *ctx)\r
111  {\r
112 @@ -151,3 +157,69 @@ _notmuch_string_map_get (notmuch_string_map_t *map, const char *key)\r
113  \r
114      return pair->value;\r
115  }\r
116 +\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
120 +{\r
121 +    notmuch_string_map_iterator_t *iter;\r
122 +\r
123 +    _notmuch_string_map_sort (map);\r
124 +\r
125 +    iter = talloc (map, notmuch_string_map_iterator_t);\r
126 +    if (unlikely (iter == NULL))\r
127 +       return NULL;\r
128 +\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
132 +    return iter;\r
133 +}\r
134 +\r
135 +notmuch_bool_t\r
136 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iterator)\r
137 +{\r
138 +    if (iterator->current == NULL)\r
139 +       return FALSE;\r
140 +\r
141 +    /* sentinel */\r
142 +    if (iterator->current->key == NULL)\r
143 +       return FALSE;\r
144 +\r
145 +    return (0 == string_cmp (iterator->key, iterator->current->key, iterator->exact));\r
146 +\r
147 +}\r
148 +\r
149 +void\r
150 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iterator)\r
151 +{\r
152 +\r
153 +    if (! _notmuch_string_map_iterator_valid (iterator))\r
154 +       return;\r
155 +\r
156 +    (iterator->current)++;\r
157 +}\r
158 +\r
159 +const char *\r
160 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator)\r
161 +{\r
162 +    if (! _notmuch_string_map_iterator_valid (iterator))\r
163 +       return NULL;\r
164 +\r
165 +    return iterator->current->key;\r
166 +}\r
167 +\r
168 +const char *\r
169 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator)\r
170 +{\r
171 +    if (! _notmuch_string_map_iterator_valid (iterator))\r
172 +       return NULL;\r
173 +\r
174 +    return iterator->current->value;\r
175 +}\r
176 +\r
177 +void\r
178 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator)\r
179 +{\r
180 +    talloc_free (iterator);\r
181 +}\r
182 -- \r
183 2.8.1\r
184 \r