Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 14 / e7864d8956a8080e179950d382db3ef813bad4
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 064CA6DE092C\r
6  for <notmuch@notmuchmail.org>; Sat,  6 Aug 2016 06:55:24 -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.003\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.003 tagged_above=-999 required=5\r
12  tests=[AWL=-0.004, HEADER_FROM_DIFFERENT_DOMAINS=0.001]\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 gW1ekHaAjiCx for <notmuch@notmuchmail.org>;\r
17  Sat,  6 Aug 2016 06:55:16 -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 A3A816DE00DF\r
20  for <notmuch@notmuchmail.org>; Sat,  6 Aug 2016 06:53:16 -0700 (PDT)\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2)\r
22  (envelope-from <bremner@tesseract.cs.unb.ca>)\r
23  id 1bW22d-0007En-Kn; Sat, 06 Aug 2016 09:53:31 -0400\r
24 Received: (nullmailer pid 4131 invoked by uid 1000);\r
25  Sat, 06 Aug 2016 13:52:44 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 4/9] lib: extend private string map API with iterators\r
29 Date: Sat,  6 Aug 2016 22:52:34 +0900\r
30 Message-Id: <1470491559-3946-5-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.8.1\r
32 In-Reply-To: <1470491559-3946-1-git-send-email-david@tethera.net>\r
33 References: <1470491559-3946-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\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: Sat, 06 Aug 2016 13:55:24 -0000\r
47 \r
48 Support for prefix based iterators is perhaps overengineering, but I\r
49 wanted to mimic the existing database_config API.\r
50 ---\r
51  lib/notmuch-private.h | 21 ++++++++++++++-\r
52  lib/string-map.c      | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
53  2 files changed, 92 insertions(+), 1 deletion(-)\r
54 \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
60  \r
61  /* string-map.c */\r
62  typedef struct _notmuch_string_map  notmuch_string_map_t;\r
63 -\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
67  \r
68 @@ -551,6 +551,25 @@ _notmuch_string_map_append (notmuch_string_map_t *map,\r
69  const char *\r
70  _notmuch_string_map_get (notmuch_string_map_t *map, const char *key);\r
71  \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
75 +\r
76 +notmuch_bool_t\r
77 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iter);\r
78 +\r
79 +void\r
80 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iter);\r
81 +\r
82 +const char *\r
83 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator);\r
84 +\r
85 +const char *\r
86 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);\r
87 +\r
88 +void\r
89 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);\r
90 +\r
91  /* tags.c */\r
92  \r
93  notmuch_tags_t *\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
100  };\r
101  \r
102 +struct _notmuch_string_map_iterator {\r
103 +    notmuch_string_pair_t *current;\r
104 +    notmuch_bool_t exact;\r
105 +    const char *key;\r
106 +};\r
107 +\r
108  notmuch_string_map_t *\r
109  _notmuch_string_map_create (const void *ctx)\r
110  {\r
111 @@ -151,3 +157,69 @@ _notmuch_string_map_get (notmuch_string_map_t *map, const char *key)\r
112  \r
113      return pair->value;\r
114  }\r
115 +\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
119 +{\r
120 +    notmuch_string_map_iterator_t *iter;\r
121 +\r
122 +    _notmuch_string_map_sort (map);\r
123 +\r
124 +    iter = talloc (map, notmuch_string_map_iterator_t);\r
125 +    if (unlikely (iter == NULL))\r
126 +       return NULL;\r
127 +\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
131 +    return iter;\r
132 +}\r
133 +\r
134 +notmuch_bool_t\r
135 +_notmuch_string_map_iterator_valid (notmuch_string_map_iterator_t *iterator)\r
136 +{\r
137 +    if (iterator->current == NULL)\r
138 +       return FALSE;\r
139 +\r
140 +    /* sentinel */\r
141 +    if (iterator->current->key == NULL)\r
142 +       return FALSE;\r
143 +\r
144 +    return (0 == string_cmp (iterator->key, iterator->current->key, iterator->exact));\r
145 +\r
146 +}\r
147 +\r
148 +void\r
149 +_notmuch_string_map_iterator_move_to_next (notmuch_string_map_iterator_t *iterator)\r
150 +{\r
151 +\r
152 +    if (! _notmuch_string_map_iterator_valid (iterator))\r
153 +       return;\r
154 +\r
155 +    (iterator->current)++;\r
156 +}\r
157 +\r
158 +const char *\r
159 +_notmuch_string_map_iterator_key (notmuch_string_map_iterator_t *iterator)\r
160 +{\r
161 +    if (! _notmuch_string_map_iterator_valid (iterator))\r
162 +       return NULL;\r
163 +\r
164 +    return iterator->current->key;\r
165 +}\r
166 +\r
167 +const char *\r
168 +_notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator)\r
169 +{\r
170 +    if (! _notmuch_string_map_iterator_valid (iterator))\r
171 +       return NULL;\r
172 +\r
173 +    return iterator->current->value;\r
174 +}\r
175 +\r
176 +void\r
177 +_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator)\r
178 +{\r
179 +    talloc_free (iterator);\r
180 +}\r
181 -- \r
182 2.8.1\r
183 \r