Leptonica 1.82.0
Image processing and image analysis suite
map.c
Go to the documentation of this file.
1/*====================================================================*
2 - Copyright (C) 2001 Leptonica. All rights reserved.
3 -
4 - Redistribution and use in source and binary forms, with or without
5 - modification, are permitted provided that the following conditions
6 - are met:
7 - 1. Redistributions of source code must retain the above copyright
8 - notice, this list of conditions and the following disclaimer.
9 - 2. Redistributions in binary form must reproduce the above
10 - copyright notice, this list of conditions and the following
11 - disclaimer in the documentation and/or other materials
12 - provided with the distribution.
13 -
14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *====================================================================*/
26
101#ifdef HAVE_CONFIG_H
102#include <config_auto.h>
103#endif /* HAVE_CONFIG_H */
104
105#include "allheaders.h"
106
107/* ------------------------------------------------------------- *
108 * Interface to Map *
109 * ------------------------------------------------------------- */
110L_AMAP *
111l_amapCreate(l_int32 keytype)
112{
113L_AMAP *m;
114
115 PROCNAME("l_amapCreate");
116
117 if (keytype != L_INT_TYPE && keytype != L_UINT_TYPE &&
118 keytype != L_FLOAT_TYPE)
119 return (L_AMAP *)ERROR_PTR("invalid keytype", procName, NULL);
120
121 m = (L_AMAP *)LEPT_CALLOC(1, sizeof(L_AMAP));
122 m->keytype = keytype;
123 return m;
124}
125
126RB_TYPE *
127l_amapFind(L_AMAP *m,
128 RB_TYPE key)
129{
130 return l_rbtreeLookup(m, key);
131}
132
133void
134l_amapInsert(L_AMAP *m,
135 RB_TYPE key,
136 RB_TYPE value)
137{
138 l_rbtreeInsert(m, key, value);
139}
140
141void
142l_amapDelete(L_AMAP *m,
143 RB_TYPE key)
144{
145 l_rbtreeDelete(m, key);
146}
147
148void
149l_amapDestroy(L_AMAP **pm)
150{
151 l_rbtreeDestroy(pm);
152}
153
155l_amapGetFirst(L_AMAP *m)
156{
157 return l_rbtreeGetFirst(m);
158}
159
161l_amapGetNext(L_AMAP_NODE *n)
162{
163 return l_rbtreeGetNext(n);
164}
165
167l_amapGetLast(L_AMAP *m)
168{
169 return l_rbtreeGetLast(m);
170}
171
173l_amapGetPrev(L_AMAP_NODE *n)
174{
175 return l_rbtreeGetPrev(n);
176}
177
178l_int32
179l_amapSize(L_AMAP *m)
180{
181 return l_rbtreeGetCount(m);
182}
183
184
185/* ------------------------------------------------------------- *
186 * Interface to Set *
187 * ------------------------------------------------------------- */
188L_ASET *
189l_asetCreate(l_int32 keytype)
190{
191L_ASET *s;
192
193 PROCNAME("l_asetCreate");
194
195 if (keytype != L_INT_TYPE && keytype != L_UINT_TYPE &&
196 keytype != L_FLOAT_TYPE)
197 return (L_ASET *)ERROR_PTR("invalid keytype", procName, NULL);
198
199 s = (L_ASET *)LEPT_CALLOC(1, sizeof(L_ASET));
200 s->keytype = keytype;
201 return s;
202}
203
204/*
205 * l_asetFind()
206 *
207 * This returns NULL if not found, non-null if it is. In the latter
208 * case, the value stored in the returned pointer has no significance.
209 */
210RB_TYPE *
211l_asetFind(L_ASET *s,
212 RB_TYPE key)
213{
214 return l_rbtreeLookup(s, key);
215}
216
217void
218l_asetInsert(L_ASET *s,
219 RB_TYPE key)
220{
221RB_TYPE value;
222
223 value.itype = 0; /* meaningless */
224 l_rbtreeInsert(s, key, value);
225}
226
227void
228l_asetDelete(L_ASET *s,
229 RB_TYPE key)
230{
231 l_rbtreeDelete(s, key);
232}
233
234void
235l_asetDestroy(L_ASET **ps)
236{
237 l_rbtreeDestroy(ps);
238}
239
241l_asetGetFirst(L_ASET *s)
242{
243 return l_rbtreeGetFirst(s);
244}
245
247l_asetGetNext(L_ASET_NODE *n)
248{
249 return l_rbtreeGetNext(n);
250}
251
253l_asetGetLast(L_ASET *s)
254{
255 return l_rbtreeGetLast(s);
256}
257
259l_asetGetPrev(L_ASET_NODE *n)
260{
261 return l_rbtreeGetPrev(n);
262}
263
264l_int32
265l_asetSize(L_ASET *s)
266{
267 return l_rbtreeGetCount(s);
268}
void l_rbtreeDelete(L_RBTREE *t, RB_TYPE key)
l_rbtreeDelete()
Definition: rbtree.c:242
L_RBTREE_NODE * l_rbtreeGetNext(L_RBTREE_NODE *n)
l_rbtreeGetNext()
Definition: rbtree.c:359
L_RBTREE_NODE * l_rbtreeGetLast(L_RBTREE *t)
l_rbtreeGetLast()
Definition: rbtree.c:394
L_RBTREE_NODE * l_rbtreeGetFirst(L_RBTREE *t)
l_rbtreeGetFirst()
Definition: rbtree.c:324
void l_rbtreeDestroy(L_RBTREE **pt)
l_rbtreeDestroy()
Definition: rbtree.c:290
RB_TYPE * l_rbtreeLookup(L_RBTREE *t, RB_TYPE key)
l_rbtreeLookup()
Definition: rbtree.c:159
L_RBTREE_NODE * l_rbtreeGetPrev(L_RBTREE_NODE *n)
l_rbtreeGetPrev()
Definition: rbtree.c:429
l_int32 l_rbtreeGetCount(L_RBTREE *t)
l_rbtreeGetCount()
Definition: rbtree.c:459
void l_rbtreeInsert(L_RBTREE *t, RB_TYPE key, RB_TYPE value)
l_rbtreeInsert()
Definition: rbtree.c:188
Definition: rbtree.h:62