Leptonica 1.85.0
Image processing and image analysis suite
Loading...
Searching...
No Matches
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 if (keytype != L_INT_TYPE && keytype != L_UINT_TYPE &&
116 keytype != L_FLOAT_TYPE)
117 return (L_AMAP *)ERROR_PTR("invalid keytype", __func__, NULL);
118
119 m = (L_AMAP *)LEPT_CALLOC(1, sizeof(L_AMAP));
120 m->keytype = keytype;
121 return m;
122}
123
124RB_TYPE *
125l_amapFind(L_AMAP *m,
126 RB_TYPE key)
127{
128 return l_rbtreeLookup(m, key);
129}
130
131void
132l_amapInsert(L_AMAP *m,
133 RB_TYPE key,
134 RB_TYPE value)
135{
136 l_rbtreeInsert(m, key, value);
137}
138
139void
140l_amapDelete(L_AMAP *m,
141 RB_TYPE key)
142{
143 l_rbtreeDelete(m, key);
144}
145
146void
147l_amapDestroy(L_AMAP **pm)
148{
149 l_rbtreeDestroy(pm);
150}
151
153l_amapGetFirst(L_AMAP *m)
154{
155 return l_rbtreeGetFirst(m);
156}
157
159l_amapGetNext(L_AMAP_NODE *n)
160{
161 return l_rbtreeGetNext(n);
162}
163
165l_amapGetLast(L_AMAP *m)
166{
167 return l_rbtreeGetLast(m);
168}
169
171l_amapGetPrev(L_AMAP_NODE *n)
172{
173 return l_rbtreeGetPrev(n);
174}
175
176l_int32
177l_amapSize(L_AMAP *m)
178{
179 return l_rbtreeGetCount(m);
180}
181
182
183/* ------------------------------------------------------------- *
184 * Interface to Set *
185 * ------------------------------------------------------------- */
186L_ASET *
187l_asetCreate(l_int32 keytype)
188{
189L_ASET *s;
190
191 if (keytype != L_INT_TYPE && keytype != L_UINT_TYPE &&
192 keytype != L_FLOAT_TYPE)
193 return (L_ASET *)ERROR_PTR("invalid keytype", __func__, NULL);
194
195 s = (L_ASET *)LEPT_CALLOC(1, sizeof(L_ASET));
196 s->keytype = keytype;
197 return s;
198}
199
200/*
201 * l_asetFind()
202 *
203 * This returns NULL if not found, non-null if it is. In the latter
204 * case, the value stored in the returned pointer has no significance.
205 */
206RB_TYPE *
207l_asetFind(L_ASET *s,
208 RB_TYPE key)
209{
210 return l_rbtreeLookup(s, key);
211}
212
213void
214l_asetInsert(L_ASET *s,
215 RB_TYPE key)
216{
217RB_TYPE value;
218
219 value.itype = 0; /* meaningless */
220 l_rbtreeInsert(s, key, value);
221}
222
223void
224l_asetDelete(L_ASET *s,
225 RB_TYPE key)
226{
227 l_rbtreeDelete(s, key);
228}
229
230void
231l_asetDestroy(L_ASET **ps)
232{
233 l_rbtreeDestroy(ps);
234}
235
237l_asetGetFirst(L_ASET *s)
238{
239 return l_rbtreeGetFirst(s);
240}
241
243l_asetGetNext(L_ASET_NODE *n)
244{
245 return l_rbtreeGetNext(n);
246}
247
249l_asetGetLast(L_ASET *s)
250{
251 return l_rbtreeGetLast(s);
252}
253
255l_asetGetPrev(L_ASET_NODE *n)
256{
257 return l_rbtreeGetPrev(n);
258}
259
260l_int32
261l_asetSize(L_ASET *s)
262{
263 return l_rbtreeGetCount(s);
264}