~ubuntu-branches/ubuntu/trusty/judy/trusty

« back to all changes in this revision

Viewing changes to src/Judy.h

  • Committer: Bazaar Package Importer
  • Author(s): Troy Heber
  • Date: 2005-03-22 06:55:53 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050322065553-syjpkd48r4re18dn
Tags: 1.0.1-5

* Moving LGPL link in copyright back to LGPL-2.1
* Cleanup of debian/rules: removed explicit refs to 32-bit archs, removed
  unnecessary nostrip, using --man dir to install man pages, moving from
  dh_movefiles to dh_install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef _JUDY_INCLUDED
2
 
#define _JUDY_INCLUDED
 
2
#define _JUDY_INCLUDED
3
3
// _________________
4
4
//
5
5
// Copyright (C) 2000 - 2002 Hewlett-Packard Company
30
30
// and some tools on some platforms.
31
31
 
32
32
 
33
 
// PLATFORM-SPECIFIC OVERHEAD:
34
 
 
35
 
#ifdef JU_FLAVOR_COV
36
 
#pragma C-Cover off     /* exclude inline functions in public header files */
37
 
#endif
38
 
 
39
 
#ifdef HAVE_INTTYPES_H
40
 
#include <inttypes.h>   /* for uint*_t types  -- obsolete ? */
41
 
#endif
42
 
 
43
 
#ifdef HAVE_STDINT_H
44
 
#include <stdint.h>     /* for uint*_t types */
45
 
#endif
46
 
 
47
 
#ifdef JU_FLAVOR_COV
48
 
#pragma C-Cover on
49
 
#endif
50
 
 
51
 
#ifdef JU_FLAVOR_COV
52
 
#pragma C-Cover off     /* exclude inline functions in public header files */
53
 
#endif
54
 
#include <stdlib.h>     /* auto-includes inttypes.h on some platforms */
55
 
#ifdef JU_FLAVOR_COV
56
 
#pragma C-Cover on
57
 
#endif
58
 
 
59
 
#ifdef __cplusplus              /* support use by C++ code */
 
33
// PLATFORM-SPECIFIC
 
34
 
 
35
#ifdef JU_WIN /* =============================================== */
 
36
 
 
37
typedef __int8           int8_t;
 
38
typedef __int16          int16_t;
 
39
typedef __int32          int32_t;
 
40
typedef __int64          int64_t;
 
41
 
 
42
typedef unsigned __int8  uint8_t;
 
43
typedef unsigned __int16 uint16_t;
 
44
typedef unsigned __int32 uint32_t;
 
45
typedef unsigned __int64 uint64_t;
 
46
 
 
47
#else /* ================ ! JU_WIN ============================= */
 
48
 
 
49
// ISO C99: 7.8 Format conversion of integer types <inttypes.h>
 
50
#include <inttypes.h>  /* if this FAILS, try #include <stdint.h> */ 
 
51
 
 
52
// ISO C99: 7.18 Integer types uint*_t 
 
53
//#include <stdint.h>  
 
54
 
 
55
#endif /* ================ ! JU_WIN ============================= */
 
56
 
 
57
// ISO C99 Standard: 7.20 General utilities
 
58
#include <stdlib.h>  
 
59
 
 
60
// ISO C99 Standard: 7.10/5.2.4.2.1 Sizes of integer types
 
61
#include <limits.h>  
 
62
 
 
63
#ifdef __cplusplus      /* support use by C++ code */
60
64
extern "C" {
61
65
#endif
62
66
 
70
74
// that the called function internally does not modify the pointer itself, such
71
75
// as, "void * const Pindex".
72
76
//
73
 
// Note that it's OK to pass a Pvoid_t to a Pcvoid_t; the latter is the same,
 
77
// Note that its OK to pass a Pvoid_t to a Pcvoid_t; the latter is the same,
74
78
// only constant.  Callers need to do this so they can also pass & Pvoid_t to
75
79
// PPvoid_t (non-constant).
76
80
 
77
 
#ifndef _PCVOID_T
78
 
#define _PCVOID_T
 
81
#ifndef _PCVOID_T
 
82
#define _PCVOID_T
79
83
typedef const void * Pcvoid_t;
80
84
#endif
81
85
 
82
 
#ifndef _PVOID_T
83
 
#define _PVOID_T
84
 
typedef void *   Pvoid_t;
85
 
typedef void ** PPvoid_t;
 
86
#ifndef _PVOID_T
 
87
#define _PVOID_T
 
88
typedef void *   Pvoid_t;
 
89
typedef void ** PPvoid_t;
86
90
#endif
87
91
 
88
92
#ifndef _WORD_T
89
93
#define _WORD_T
90
 
typedef unsigned long    Word_t, * PWord_t;  // expect 32-bit or 64-bit words.
 
94
typedef unsigned long    Word_t, * PWord_t;  // expect 32-bit or 64-bit words.
91
95
#endif
92
96
 
93
 
#ifndef NULL
94
 
#define NULL 0
 
97
#ifndef NULL
 
98
#define NULL 0
95
99
#endif
96
100
 
97
101
 
100
104
//
101
105
// Judy error numbers:
102
106
//
103
 
// Note:  These are an enum so there's a related typedef, but the numbers are
 
107
// Note:  These are an enum so theres a related typedef, but the numbers are
104
108
// spelled out so you can map a number back to its name.
105
109
 
106
 
typedef enum            // uint8_t -- but C does not support this type of enum.
 
110
typedef enum            // uint8_t -- but C does not support this type of enum.
107
111
{
108
112
 
109
113
// Note:  JU_ERRNO_NONE and JU_ERRNO_FULL are not real errors.  They specify
113
117
// be unambiguously represented in a 32-bit word, and will never occur on a
114
118
// 64-bit system.
115
119
 
116
 
        JU_ERRNO_NONE           = 0,
117
 
        JU_ERRNO_FULL           = 1,
118
 
        JU_ERRNO_NFMAX          = JU_ERRNO_FULL,
 
120
        JU_ERRNO_NONE           = 0,
 
121
        JU_ERRNO_FULL           = 1,
 
122
        JU_ERRNO_NFMAX          = JU_ERRNO_FULL,
119
123
 
120
124
// JU_ERRNO_NOMEM comes from malloc(3C) when Judy cannot obtain needed memory.
121
125
// The system errno value is also set to ENOMEM.  This error can be recoverable
124
128
// TBD:  Currently there is no guarantee the Judy array has no memory leaks
125
129
// upon JU_ERRNO_NOMEM.
126
130
 
127
 
        JU_ERRNO_NOMEM          = 2,
 
131
        JU_ERRNO_NOMEM          = 2,
128
132
 
129
133
// Problems with parameters from the calling program:
130
134
//
135
139
// higher numbers), mean:  A non-null array was passed in where a null pointer
136
140
// was required; PValue was null; and unsorted indexes were detected.
137
141
 
138
 
        JU_ERRNO_NULLPPARRAY    = 3,    // see above.
139
 
        JU_ERRNO_NONNULLPARRAY  = 10,   // see above.
140
 
        JU_ERRNO_NULLPINDEX     = 4,    // see above.
141
 
        JU_ERRNO_NULLPVALUE     = 11,   // see above.
142
 
        JU_ERRNO_NOTJUDY1       = 5,    // PArray is not to a Judy1 array.
143
 
        JU_ERRNO_NOTJUDYL       = 6,    // PArray is not to a JudyL array.
144
 
        JU_ERRNO_NOTJUDYSL      = 7,    // PArray is not to a JudySL array.
145
 
        JU_ERRNO_UNSORTED       = 12,   // see above.
 
142
        JU_ERRNO_NULLPPARRAY    = 3,    // see above.
 
143
        JU_ERRNO_NONNULLPARRAY  = 10,   // see above.
 
144
        JU_ERRNO_NULLPINDEX     = 4,    // see above.
 
145
        JU_ERRNO_NULLPVALUE     = 11,   // see above.
 
146
        JU_ERRNO_NOTJUDY1       = 5,    // PArray is not to a Judy1 array.
 
147
        JU_ERRNO_NOTJUDYL       = 6,    // PArray is not to a JudyL array.
 
148
        JU_ERRNO_NOTJUDYSL      = 7,    // PArray is not to a JudySL array.
 
149
        JU_ERRNO_UNSORTED       = 12,   // see above.
146
150
 
147
151
// Errors below this point are not recoverable; further tries to access the
148
152
// Judy array might result in EFAULT and a core dump:
150
154
// JU_ERRNO_OVERRUN occurs when Judy detects, upon reallocation, that a block
151
155
// of memory in its own freelist was modified since being freed.
152
156
 
153
 
        JU_ERRNO_OVERRUN        = 8,
 
157
        JU_ERRNO_OVERRUN        = 8,
154
158
 
155
159
// JU_ERRNO_CORRUPT occurs when Judy detects an impossible value in a Judy data
156
160
// structure:
158
162
// Note:  The Judy data structure contains some redundant elements that support
159
163
// this type of checking.
160
164
 
161
 
        JU_ERRNO_CORRUPT        = 9
 
165
        JU_ERRNO_CORRUPT        = 9
162
166
 
163
167
// Warning:  At least some C or C++ compilers do not tolerate a trailing comma
164
168
// above here.  At least we know of one case, in aCC; see JAGad58928.
174
178
 
175
179
// This structure should be declared on the stack in a threaded process.
176
180
 
177
 
typedef struct _JUDY_ERROR_STRUCT
 
181
typedef struct J_UDY_ERROR_STRUCT
178
182
{
179
 
        JU_Errno_t je_Errno;            // one of the enums above.
180
 
        int        je_ErrID;            // often an internal source line number.
181
 
        Word_t     je_reserved[4];      // for future backward compatibility.
 
183
        JU_Errno_t je_Errno;            // one of the enums above.
 
184
        int        je_ErrID;            // often an internal source line number.
 
185
        Word_t     je_reserved[4];      // for future backward compatibility.
182
186
 
183
187
} JError_t, * PJError_t;
184
188
 
187
191
//
188
192
// Fields from error struct:
189
193
 
190
 
#define JU_ERRNO(PJError)  ((PJError)->je_Errno)
191
 
#define JU_ERRID(PJError)  ((PJError)->je_ErrID)
 
194
#define JU_ERRNO(PJError)  ((PJError)->je_Errno)
 
195
#define JU_ERRID(PJError)  ((PJError)->je_ErrID)
192
196
 
193
197
// For checking return values from various Judy functions:
194
198
//
196
200
// (~0UL), to avoid a compiler "overflow in implicit constant conversion"
197
201
// warning.
198
202
 
199
 
#define   JERR (-1)                     /* functions returning int or Word_t */
200
 
#define  PJERR ((Pvoid_t)  (~0UL))      /* mainly for use here, see below    */
201
 
#define PPJERR ((PPvoid_t) (~0UL))      /* functions that return PPvoid_t    */
 
203
#define   JERR (-1)                     /* functions returning int or Word_t */
 
204
#define  PJERR ((Pvoid_t)  (~0UL))      /* mainly for use here, see below    */
 
205
#define PPJERR ((PPvoid_t) (~0UL))      /* functions that return PPvoid_t    */
202
206
 
203
207
// Convenience macro for when detailed error information (PJError_t) is not
204
208
// desired by the caller; a purposely short name:
205
209
 
206
 
#define PJE0  ((PJError_t) NULL)
 
210
#define PJE0  ((PJError_t) NULL)
207
211
 
208
212
 
209
213
// ****************************************************************************
210
214
// JUDY FUNCTIONS:
211
215
//
212
 
// PJE is a shorthand for use below:
213
 
 
214
 
#define _PJE  PJError_t PJError
215
 
 
216
 
extern int      __Judy1Test(     Pvoid_t   Pjpm,   Word_t   Index);
217
 
extern int      Judy1Test(       Pcvoid_t  PArray, Word_t   Index,   _PJE);
218
 
extern int      Judy1Set(        PPvoid_t PPArray, Word_t   Index,   _PJE);
219
 
extern int      Judy1SetArray(   PPvoid_t PPArray, Word_t   Count,
220
 
                                             const Word_t * const PIndex,
221
 
                                                                     _PJE);
222
 
extern int      Judy1Unset(      PPvoid_t PPArray, Word_t   Index,   _PJE);
223
 
extern Word_t   Judy1Count(      Pcvoid_t  PArray, Word_t   Index1,
224
 
                                                   Word_t   Index2,  _PJE);
225
 
extern int      Judy1ByCount(    Pcvoid_t  PArray, Word_t   Count,
226
 
                                                   Word_t * PIndex,  _PJE);
227
 
extern Word_t   Judy1FreeArray(  PPvoid_t PPArray,                   _PJE);
228
 
extern Word_t   Judy1MemUsed(    Pcvoid_t  PArray);
229
 
extern Word_t   Judy1MemActive(  Pcvoid_t  PArray);
230
 
extern int      Judy1First(      Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
231
 
extern int      Judy1Next(       Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
232
 
extern int      __Judy1Next(     Pvoid_t   Pjpm,   Word_t * PIndex);
233
 
extern int      Judy1Last(       Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
234
 
extern int      Judy1Prev(       Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
235
 
extern int      Judy1FirstEmpty( Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
236
 
extern int      Judy1NextEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
237
 
extern int      Judy1LastEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
238
 
extern int      Judy1PrevEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
239
 
 
240
 
extern PPvoid_t __JudyLGet(      Pvoid_t   Pjpm,   Word_t    Index);
241
 
extern PPvoid_t JudyLGet(        Pcvoid_t  PArray, Word_t    Index,  _PJE);
242
 
extern PPvoid_t JudyLIns(        PPvoid_t PPArray, Word_t    Index,  _PJE);
243
 
extern int      JudyLInsArray(   PPvoid_t PPArray, Word_t    Count,
244
 
                                             const Word_t * const PIndex,
245
 
                                             const Word_t * const PValue,
246
 
                                                                     _PJE);
247
 
extern int      JudyLDel(        PPvoid_t PPArray, Word_t    Index,  _PJE);
248
 
extern Word_t   JudyLCount(      Pcvoid_t  PArray, Word_t    Index1,
249
 
                                                   Word_t    Index2, _PJE);
250
 
extern PPvoid_t JudyLByCount(    Pcvoid_t  PArray, Word_t    Count,
251
 
                                                   Word_t *  PIndex, _PJE);
252
 
extern Word_t   JudyLFreeArray(  PPvoid_t PPArray,                   _PJE);
253
 
extern Word_t   JudyLMemUsed(    Pcvoid_t  PArray);
254
 
extern Word_t   JudyLMemActive(  Pcvoid_t  PArray);
255
 
extern PPvoid_t JudyLFirst(      Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
256
 
extern PPvoid_t JudyLNext(       Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
257
 
extern PPvoid_t __JudyLNext(     Pvoid_t   Pjpm,   Word_t * PIndex);
258
 
extern PPvoid_t JudyLLast(       Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
259
 
extern PPvoid_t JudyLPrev(       Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
260
 
extern int      JudyLFirstEmpty( Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
261
 
extern int      JudyLNextEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
262
 
extern int      JudyLLastEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
263
 
extern int      JudyLPrevEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  _PJE);
264
 
 
265
 
extern PPvoid_t JudySLGet(       Pcvoid_t  PArray, const char * Index, _PJE);
266
 
extern PPvoid_t JudySLIns(       PPvoid_t PPArray, const char * Index, _PJE);
267
 
extern int      JudySLDel(       PPvoid_t PPArray, const char * Index, _PJE);
268
 
extern Word_t   JudySLFreeArray( PPvoid_t PPArray,                     _PJE);
269
 
extern PPvoid_t JudySLFirst(     Pcvoid_t  PArray,       char * Index, _PJE);
270
 
extern PPvoid_t JudySLNext(      Pcvoid_t  PArray,       char * Index, _PJE);
271
 
extern PPvoid_t JudySLLast(      Pcvoid_t  PArray,       char * Index, _PJE);
272
 
extern PPvoid_t JudySLPrev(      Pcvoid_t  PArray,       char * Index, _PJE);
 
216
// P_JE is a shorthand for use below:
 
217
 
 
218
#define P_JE  PJError_t PJError
 
219
 
 
220
// ****************************************************************************
 
221
// JUDY1 FUNCTIONS:
 
222
 
 
223
extern int      j__udy1Test(     Pvoid_t   Pjpm,   Word_t   Index);
 
224
extern int      Judy1Test(       Pcvoid_t  PArray, Word_t   Index,   P_JE);
 
225
extern int      Judy1Set(        PPvoid_t PPArray, Word_t   Index,   P_JE);
 
226
extern int      Judy1SetArray(   PPvoid_t PPArray, Word_t   Count,
 
227
                                             const Word_t * const PIndex,
 
228
                                                                     P_JE);
 
229
extern int      Judy1Unset(      PPvoid_t PPArray, Word_t   Index,   P_JE);
 
230
extern Word_t   Judy1Count(      Pcvoid_t  PArray, Word_t   Index1,
 
231
                                                   Word_t   Index2,  P_JE);
 
232
extern int      Judy1ByCount(    Pcvoid_t  PArray, Word_t   Count,
 
233
                                                   Word_t * PIndex,  P_JE);
 
234
extern Word_t   Judy1FreeArray(  PPvoid_t PPArray,                   P_JE);
 
235
extern Word_t   Judy1MemUsed(    Pcvoid_t  PArray);
 
236
extern Word_t   Judy1MemActive(  Pcvoid_t  PArray);
 
237
extern int      Judy1First(      Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
238
extern int      Judy1Next(       Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
239
extern int      j__udy1Next(     Pvoid_t   Pjpm,   Word_t * PIndex);
 
240
extern int      Judy1Last(       Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
241
extern int      Judy1Prev(       Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
242
extern int      Judy1FirstEmpty( Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
243
extern int      Judy1NextEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
244
extern int      Judy1LastEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
245
extern int      Judy1PrevEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
246
 
 
247
extern PPvoid_t j__udyLGet(      Pvoid_t   Pjpm,   Word_t    Index);
 
248
extern PPvoid_t JudyLGet(        Pcvoid_t  PArray, Word_t    Index,  P_JE);
 
249
extern PPvoid_t JudyLIns(        PPvoid_t PPArray, Word_t    Index,  P_JE);
 
250
extern int      JudyLInsArray(   PPvoid_t PPArray, Word_t    Count,
 
251
                                             const Word_t * const PIndex,
 
252
                                             const Word_t * const PValue,
 
253
 
 
254
// ****************************************************************************
 
255
// JUDYL FUNCTIONS:
 
256
                                                                     P_JE);
 
257
extern int      JudyLDel(        PPvoid_t PPArray, Word_t    Index,  P_JE);
 
258
extern Word_t   JudyLCount(      Pcvoid_t  PArray, Word_t    Index1,
 
259
                                                   Word_t    Index2, P_JE);
 
260
extern PPvoid_t JudyLByCount(    Pcvoid_t  PArray, Word_t    Count,
 
261
                                                   Word_t *  PIndex, P_JE);
 
262
extern Word_t   JudyLFreeArray(  PPvoid_t PPArray,                   P_JE);
 
263
extern Word_t   JudyLMemUsed(    Pcvoid_t  PArray);
 
264
extern Word_t   JudyLMemActive(  Pcvoid_t  PArray);
 
265
extern PPvoid_t JudyLFirst(      Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
266
extern PPvoid_t JudyLNext(       Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
267
extern PPvoid_t j__udyLNext(     Pvoid_t   Pjpm,   Word_t * PIndex);
 
268
extern PPvoid_t JudyLLast(       Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
269
extern PPvoid_t JudyLPrev(       Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
270
extern int      JudyLFirstEmpty( Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
271
extern int      JudyLNextEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
272
extern int      JudyLLastEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
273
extern int      JudyLPrevEmpty(  Pcvoid_t  PArray, Word_t * PIndex,  P_JE);
 
274
 
 
275
// ****************************************************************************
 
276
// JUDYSL FUNCTIONS:
 
277
 
 
278
extern PPvoid_t JudySLGet(       Pcvoid_t, const uint8_t * Index, P_JE);
 
279
extern PPvoid_t JudySLIns(       PPvoid_t, const uint8_t * Index, P_JE);
 
280
extern int      JudySLDel(       PPvoid_t, const uint8_t * Index, P_JE);
 
281
extern Word_t   JudySLFreeArray( PPvoid_t,                        P_JE);
 
282
extern PPvoid_t JudySLFirst(     Pcvoid_t,       uint8_t * Index, P_JE);
 
283
extern PPvoid_t JudySLNext(      Pcvoid_t,       uint8_t * Index, P_JE);
 
284
extern PPvoid_t JudySLLast(      Pcvoid_t,       uint8_t * Index, P_JE);
 
285
extern PPvoid_t JudySLPrev(      Pcvoid_t,       uint8_t * Index, P_JE);
 
286
 
 
287
// ****************************************************************************
 
288
// JUDYHSL FUNCTIONS:
 
289
 
 
290
extern PPvoid_t JudyHSGet(       Pcvoid_t,  void *, Word_t);
 
291
extern PPvoid_t JudyHSIns(       PPvoid_t,  void *, Word_t, P_JE);
 
292
extern int      JudyHSDel(       PPvoid_t,  void *, Word_t, P_JE);
 
293
extern Word_t   JudyHSFreeArray( PPvoid_t,                  P_JE);
273
294
 
274
295
extern const char *Judy1MallocSizes;
275
296
extern const char *JudyLMallocSizes;
276
297
 
277
 
 
278
 
// JUDYL ARRAY POINTER LOW BITS PROTECTED FOR USE BY APPLICATIONS:
279
 
//
280
 
// The JLAP_INVALID pattern never appears in a JudyL array pointer.  Hence
281
 
// applications that build trees of JudyL arrays can use this pattern to
282
 
// distinguish a JudyL array value that is a pointer to another JudyL array
283
 
// from one that is a pointer to some other, application-defined object.
284
 
//
285
 
// Note:  J1LAP_NEXTTYPE is used to build a mask, but must agree with the
286
 
// J1*/JL* values below.
287
 
//
288
 
// Note:  Use old-style comments here because some tools insist on it for
289
 
// macros referenced in other macros.
290
 
 
291
 
#define J1LAP_NEXTTYPE  0x8             /* first enum value beyond J*AP types */
292
 
 
293
 
#define JLAP_MASK    (J1LAP_NEXTTYPE-1) /* mask pointer for JLAP_INVALID     */
294
 
#define JLAP_INVALID    0x4             /* not a JLAP                        */
295
 
 
296
 
 
297
 
// JUDY ARRAY POINTER LOW BITS = TYPES:
298
 
//
299
 
// Note:  Judy libraries can be constructed with JLAPLEAF_POPU* unused, but
300
 
// external callers cannot tell if this is the case, so in this header file
301
 
// they are still defined and supported.
302
 
 
303
 
enum {
304
 
        JLAPNULL        = 0x0,          /* must be == 0                     */
305
 
        J1APNULL        = 0x0,          /* must be == 0                     */
306
 
        JLAPLEAF        = 0x1,          /* Word_t leafW with Pop0 in word 1 */
307
 
//      JLAPLEAF_POPU2  = 0x2,          /* Word_t leafW with Pop1 == 2      */
308
 
        JLAPBRANCH      = 0x3,          /* pointer to jLpm_t => branch      */
309
 
        JLAPINVALID     = JLAP_INVALID, /* not a JLAP, assume == 4          */
310
 
//      JLAPLEAF_POPU1  = 0x5,          /* Word_t leafW with Pop1 == 1      */
311
 
        J1APLEAF        = 0x6,          /* Word_t leafW with Pop0 in word 1 */
312
 
        J1APBRANCH      = 0x7           /* pointer to j1pm_t => branch      */
313
 
};
314
 
 
 
298
// ****************************************************************************
 
299
// JUDY memory interface to malloc() FUNCTIONS:
 
300
 
 
301
extern Word_t JudyMalloc(Word_t);               // words reqd => words allocd.
 
302
extern Word_t JudyMallocVirtual(Word_t);        // words reqd => words allocd.
 
303
extern void   JudyFree(Pvoid_t, Word_t);        // free, size in words.
 
304
extern void   JudyFreeVirtual(Pvoid_t, Word_t); // free, size in words.
 
305
 
 
306
#define JLAP_INVALID    0x1     /* flag to mark pointer "not a Judy array" */
315
307
 
316
308
// ****************************************************************************
317
309
// MACRO EQUIVALENTS FOR JUDY FUNCTIONS:
330
322
// Note: the back-slashes are removed because some compilers will not accept
331
323
// them in comments.
332
324
//
333
 
// void HandleJudyError(char *, int, char *, int, int);
 
325
// void HandleJudyError(uint8_t *, int, uint8_t *, int, int);
334
326
// #define JUDYERROR(CallerFile, CallerLine, JudyFunc, JudyErrno, JudyErrID)
335
 
//  {
 
327
// {
336
328
//    HandleJudyError(CallerFile, CallerLine, JudyFunc, JudyErrno, JudyErrID);
337
 
//  }
 
329
// }
338
330
//
339
331
// The routine HandleJudyError could do checking on specific error numbers and
340
332
// print a different message dependent on the error.
348
340
// 5.  JudyErrID:   The je_ErrID field described above.
349
341
 
350
342
#ifndef JUDYERROR_NOTEST
351
 
#ifndef JUDYERROR       /* supply a default error macro */
352
 
#ifdef JU_FLAVOR_COV
353
 
#pragma C-Cover off     /* exclude inline functions in public header files */
354
 
#endif
 
343
#ifndef JUDYERROR       /* supply a default error macro */
355
344
#include <stdio.h>
356
 
#ifdef JU_FLAVOR_COV
357
 
#pragma C-Cover on
358
 
#endif
359
345
 
360
346
#define JUDYERROR(CallerFile, CallerLine, JudyFunc, JudyErrno, JudyErrID) \
361
 
        {                                                       \
362
 
            (void) fprintf(stderr, "File '%s', line %d: %s(), " \
363
 
                           "JU_ERRNO_* == %d, ID == %d\n",      \
364
 
                           CallerFile, CallerLine,              \
365
 
                           JudyFunc, JudyErrno, JudyErrID);     \
366
 
            exit(1);                                            \
367
 
        }
 
347
    {                                                                     \
 
348
        (void) fprintf(stderr, "File '%s', line %d: %s(), "               \
 
349
           "JU_ERRNO_* == %d, ID == %d\n",                                \
 
350
           CallerFile, CallerLine,                                        \
 
351
           JudyFunc, JudyErrno, JudyErrID);                               \
 
352
        exit(1);                                                          \
 
353
    }
368
354
 
369
355
#endif /* JUDYERROR */
370
356
#endif /* JUDYERROR_NOTEST */
390
376
//
391
377
// or:
392
378
//
393
 
//   JLI(Pvalue, PArray, Index);
394
 
//   if (Pvalue == PJERR) goto ...error
 
379
//   JLI(PValue, PArray, Index);
 
380
//   if (PValue == PJERR) goto ...error
395
381
 
396
382
 
397
383
// Internal shorthand macros for writing the J1S, etc. macros:
400
386
 
401
387
// "Judy Set Error":
402
388
 
403
 
#define _JSE(FuncName,Errno)  ((void) 0)
 
389
#define J_SE(FuncName,Errno)  ((void) 0)
404
390
 
405
 
// Note:  In each _J*() case below, the digit is the number of key parameters
406
 
// to the Judy*() call.  Just assign the Func result to the caller's Rc value
 
391
// Note:  In each J_*() case below, the digit is the number of key parameters
 
392
// to the Judy*() call.  Just assign the Func result to the callers Rc value
407
393
// without a cast because none is required, and this keeps the API simpler.
408
 
// However, a family of different _J*() macros is needed to support the
 
394
// However, a family of different J_*() macros is needed to support the
409
395
// different numbers of key parameters (0,1,2) and the Func return type.
410
396
//
411
397
// In the names below, "I" = integer result; "P" = pointer result.  Note, the
412
 
// Funcs for _J*P() return PPvoid_t, but cast this to a Pvoid_t for flexible,
 
398
// Funcs for J_*P() return PPvoid_t, but cast this to a Pvoid_t for flexible,
413
399
// error-free assignment, and then compare to PJERR.
414
400
 
415
 
#define _J0I(Rc,PArray,Func,FuncName) \
416
 
        { (Rc) = Func(PArray, PJE0); }
417
 
 
418
 
#define _J1I(Rc,PArray,Index,Func,FuncName) \
419
 
        { (Rc) = Func(PArray, Index, PJE0); }
420
 
 
421
 
#define _J1P(PV,PArray,Index,Func,FuncName) \
422
 
        { (PV) = (Pvoid_t) Func(PArray, Index, PJE0); }
423
 
 
424
 
#define _J2I(Rc,PArray,Index,Arg2,Func,FuncName) \
425
 
        { (Rc) = Func(PArray, Index, Arg2, PJE0); }
426
 
 
427
 
#define _J2C(Rc,PArray,Index1,Index2,Func,FuncName) \
428
 
        { (Rc) = Func(PArray, Index1, Index2, PJE0); }
429
 
 
430
 
#define _J2P(PV,PArray,Index,Arg2,Func,FuncName) \
431
 
        { (PV) = (Pvoid_t) Func(PArray, Index, Arg2, PJE0); }
 
401
#define J_0I(Rc,PArray,Func,FuncName) \
 
402
        { (Rc) = Func(PArray, PJE0); }
 
403
 
 
404
#define J_1I(Rc,PArray,Index,Func,FuncName) \
 
405
        { (Rc) = Func(PArray, Index, PJE0); }
 
406
 
 
407
#define J_1P(PV,PArray,Index,Func,FuncName) \
 
408
        { (PV) = (Pvoid_t) Func(PArray, Index, PJE0); }
 
409
 
 
410
#define J_2I(Rc,PArray,Index,Arg2,Func,FuncName) \
 
411
        { (Rc) = Func(PArray, Index, Arg2, PJE0); }
 
412
 
 
413
#define J_2C(Rc,PArray,Index1,Index2,Func,FuncName) \
 
414
        { (Rc) = Func(PArray, Index1, Index2, PJE0); }
 
415
 
 
416
#define J_2P(PV,PArray,Index,Arg2,Func,FuncName) \
 
417
        { (PV) = (Pvoid_t) Func(PArray, Index, Arg2, PJE0); }
432
418
 
433
419
// Variations for Judy*Set/InsArray functions:
434
420
 
435
 
#define _J2AI(Rc,PArray,Count,PIndex,Func,FuncName) \
436
 
        { (Rc) = Func(PArray, Count, PIndex, PJE0); }
437
 
#define _J3AI(Rc,PArray,Count,PIndex,PValue,Func,FuncName) \
438
 
        { (Rc) = Func(PArray, Count, PIndex, PValue, PJE0); }
 
421
#define J_2AI(Rc,PArray,Count,PIndex,Func,FuncName) \
 
422
        { (Rc) = Func(PArray, Count, PIndex, PJE0); }
 
423
#define J_3AI(Rc,PArray,Count,PIndex,PValue,Func,FuncName) \
 
424
        { (Rc) = Func(PArray, Count, PIndex, PValue, PJE0); }
439
425
 
440
426
#else /* ================ ! JUDYERROR_NOTEST ============================= */
441
427
 
442
 
#define _JE(FuncName,PJE) \
443
 
        JUDYERROR(__FILE__, __LINE__, FuncName, JU_ERRNO(PJE), JU_ERRID(PJE))
444
 
 
445
 
#define _JSE(FuncName,Errno)                                            \
446
 
        {                                                               \
447
 
            JError_t _JError;                                           \
448
 
            JU_ERRNO(&_JError) = (Errno);                               \
449
 
            JU_ERRID(&_JError) = __LINE__;                              \
450
 
            _JE(FuncName, &_JError);                                    \
451
 
        }
452
 
 
453
 
// Note:  In each _J*() case below, the digit is the number of key parameters
454
 
// to the Judy*() call.  Just assign the Func result to the caller's Rc value
 
428
#define J_E(FuncName,PJE) \
 
429
        JUDYERROR(__FILE__, __LINE__, FuncName, JU_ERRNO(PJE), JU_ERRID(PJE))
 
430
 
 
431
#define J_SE(FuncName,Errno)                                            \
 
432
        {                                                               \
 
433
            JError_t J_Error;                                           \
 
434
            JU_ERRNO(&J_Error) = (Errno);                               \
 
435
            JU_ERRID(&J_Error) = __LINE__;                              \
 
436
            J_E(FuncName, &J_Error);                                    \
 
437
        }
 
438
 
 
439
// Note:  In each J_*() case below, the digit is the number of key parameters
 
440
// to the Judy*() call.  Just assign the Func result to the callers Rc value
455
441
// without a cast because none is required, and this keeps the API simpler.
456
 
// However, a family of different _J*() macros is needed to support the
 
442
// However, a family of different J_*() macros is needed to support the
457
443
// different numbers of key parameters (0,1,2) and the Func return type.
458
444
//
459
445
// In the names below, "I" = integer result; "P" = pointer result.  Note, the
460
 
// Funcs for _J*P() return PPvoid_t, but cast this to a Pvoid_t for flexible,
 
446
// Funcs for J_*P() return PPvoid_t, but cast this to a Pvoid_t for flexible,
461
447
// error-free assignment, and then compare to PJERR.
462
448
 
463
 
#define _J0I(Rc,PArray,Func,FuncName)                                   \
464
 
        {                                                               \
465
 
            JError_t _JError;                                           \
466
 
            if (((Rc) = Func(PArray, &_JError)) == JERR)                \
467
 
                _JE(FuncName, &_JError);                                \
468
 
        }
469
 
 
470
 
#define _J1I(Rc,PArray,Index,Func,FuncName)                             \
471
 
        {                                                               \
472
 
            JError_t _JError;                                           \
473
 
            if (((Rc) = Func(PArray, Index, &_JError)) == JERR)         \
474
 
                _JE(FuncName, &_JError);                                \
475
 
        }
476
 
 
477
 
#define _J1P(Rc,PArray,Index,Func,FuncName)                             \
478
 
        {                                                               \
479
 
            JError_t _JError;                                           \
480
 
            if (((Rc) = (Pvoid_t) Func(PArray, Index, &_JError)) == PJERR) \
481
 
                _JE(FuncName, &_JError);                                \
482
 
        }
483
 
 
484
 
#define _J2I(Rc,PArray,Index,Arg2,Func,FuncName)                        \
485
 
        {                                                               \
486
 
            JError_t _JError;                                           \
487
 
            if (((Rc) = Func(PArray, Index, Arg2, &_JError)) == JERR)   \
488
 
                _JE(FuncName, &_JError);                                \
489
 
        }
 
449
#define J_0I(Rc,PArray,Func,FuncName)                                   \
 
450
        {                                                               \
 
451
            JError_t J_Error;                                           \
 
452
            if (((Rc) = Func(PArray, &J_Error)) == JERR)                \
 
453
                J_E(FuncName, &J_Error);                                \
 
454
        }
 
455
 
 
456
#define J_1I(Rc,PArray,Index,Func,FuncName)                             \
 
457
        {                                                               \
 
458
            JError_t J_Error;                                           \
 
459
            if (((Rc) = Func(PArray, Index, &J_Error)) == JERR)         \
 
460
                J_E(FuncName, &J_Error);                                \
 
461
        }
 
462
 
 
463
#define J_1P(Rc,PArray,Index,Func,FuncName)                             \
 
464
        {                                                               \
 
465
            JError_t J_Error;                                           \
 
466
            if (((Rc) = (Pvoid_t) Func(PArray, Index, &J_Error)) == PJERR) \
 
467
                J_E(FuncName, &J_Error);                                \
 
468
        }
 
469
 
 
470
#define J_2I(Rc,PArray,Index,Arg2,Func,FuncName)                        \
 
471
        {                                                               \
 
472
            JError_t J_Error;                                           \
 
473
            if (((Rc) = Func(PArray, Index, Arg2, &J_Error)) == JERR)   \
 
474
                J_E(FuncName, &J_Error);                                \
 
475
        }
490
476
 
491
477
// Variation for Judy*Count functions, which return 0, not JERR, for error (and
492
478
// also for other non-error cases):
493
479
//
494
480
// Note:  JU_ERRNO_NFMAX should only apply to 32-bit Judy1, but this header
495
 
// file lacks the necessary ifdef's to make it go away otherwise, so always
 
481
// file lacks the necessary ifdefs to make it go away otherwise, so always
496
482
// check against it.
497
483
 
498
 
#define _J2C(Rc,PArray,Index1,Index2,Func,FuncName)                     \
499
 
        {                                                               \
500
 
            JError_t _JError;                                           \
501
 
            if ((((Rc) = Func(PArray, Index1, Index2, &_JError)) == 0)  \
502
 
             && (JU_ERRNO(&_JError) > JU_ERRNO_NFMAX))                  \
503
 
            {                                                           \
504
 
                _JE(FuncName, &_JError);                                \
505
 
            }                                                           \
506
 
        }
 
484
#define J_2C(Rc,PArray,Index1,Index2,Func,FuncName)                     \
 
485
        {                                                               \
 
486
            JError_t J_Error;                                           \
 
487
            if ((((Rc) = Func(PArray, Index1, Index2, &J_Error)) == 0)  \
 
488
             && (JU_ERRNO(&J_Error) > JU_ERRNO_NFMAX))                  \
 
489
            {                                                           \
 
490
                J_E(FuncName, &J_Error);                                \
 
491
            }                                                           \
 
492
        }
507
493
 
508
 
#define _J2P(PV,PArray,Index,Arg2,Func,FuncName)                        \
509
 
        {                                                               \
510
 
            JError_t _JError;                                           \
511
 
            if (((PV) = (Pvoid_t) Func(PArray, Index, Arg2, &_JError))  \
512
 
                == PJERR) _JE(FuncName, &_JError);                      \
513
 
        }
 
494
#define J_2P(PV,PArray,Index,Arg2,Func,FuncName)                        \
 
495
        {                                                               \
 
496
            JError_t J_Error;                                           \
 
497
            if (((PV) = (Pvoid_t) Func(PArray, Index, Arg2, &J_Error))  \
 
498
                == PJERR) J_E(FuncName, &J_Error);                      \
 
499
        }
514
500
 
515
501
// Variations for Judy*Set/InsArray functions:
516
502
 
517
 
#define _J2AI(Rc,PArray,Count,PIndex,Func,FuncName)                     \
518
 
        {                                                               \
519
 
            JError_t _JError;                                           \
520
 
            if (((Rc) = Func(PArray, Count, PIndex, &_JError)) == JERR) \
521
 
                _JE(FuncName, &_JError);                                \
522
 
        }
 
503
#define J_2AI(Rc,PArray,Count,PIndex,Func,FuncName)                     \
 
504
        {                                                               \
 
505
            JError_t J_Error;                                           \
 
506
            if (((Rc) = Func(PArray, Count, PIndex, &J_Error)) == JERR) \
 
507
                J_E(FuncName, &J_Error);                                \
 
508
        }
523
509
 
524
 
#define _J3AI(Rc,PArray,Count,PIndex,PValue,Func,FuncName)              \
525
 
        {                                                               \
526
 
            JError_t _JError;                                           \
527
 
            if (((Rc) = Func(PArray, Count, PIndex, PValue, &_JError))  \
528
 
                == JERR) _JE(FuncName, &_JError);                       \
529
 
        }
 
510
#define J_3AI(Rc,PArray,Count,PIndex,PValue,Func,FuncName)              \
 
511
        {                                                               \
 
512
            JError_t J_Error;                                           \
 
513
            if (((Rc) = Func(PArray, Count, PIndex, PValue, &J_Error))  \
 
514
                == JERR) J_E(FuncName, &J_Error);                       \
 
515
        }
530
516
 
531
517
#endif /* ================ ! JUDYERROR_NOTEST ============================= */
532
518
 
533
519
// Some of the macros are special cases that use inlined shortcuts for speed
534
520
// with root-level leaves:
535
521
 
536
 
#define J1T(Rc,PArray,Index)                                    \
537
 
{                                                               \
538
 
    Word_t  _jpt = ((Word_t) (PArray)) & JLAP_MASK;             \
539
 
    PWord_t _PL  = (PWord_t) (((Word_t) (PArray)) ^ _jpt);      \
540
 
    (Rc)         = 0;                                           \
541
 
                                                                \
542
 
    if (_jpt == J1APLEAF)                                       \
543
 
    {                                                           \
544
 
        Word_t  _pop1 = _PL[0] + 1;                             \
545
 
        if ((Index) <= _PL[_pop1])                              \
546
 
        {                                                       \
547
 
            for(;;)                                             \
548
 
            {                                                   \
549
 
                if (*(++_PL) >= (Index))                        \
550
 
                {                                               \
551
 
                    if (*_PL == (Index)) (Rc) = 1;              \
552
 
                    break;                                      \
553
 
                }                                               \
554
 
            }                                                   \
555
 
        }                                                       \
556
 
    }                                                           \
557
 
    else if (_jpt == J1APBRANCH)                                \
558
 
    {                                                           \
559
 
        /* note: no error possible here: */                     \
560
 
        (Rc) = __Judy1Test((Pvoid_t) _PL, (Index));             \
561
 
    }                                                           \
562
 
    else if (PArray != (Pvoid_t) NULL)                          \
563
 
    {                                                           \
564
 
        (Rc) = JERR;                                            \
565
 
        _JSE("Judy1Test", JU_ERRNO_NOTJUDY1);                   \
566
 
    }                                                           \
567
 
}
568
 
 
569
 
#define J1S( Rc,    PArray,   Index) \
570
 
        _J1I(Rc, (&(PArray)), Index,  Judy1Set,   "Judy1Set")
571
 
#define J1SA(Rc,    PArray,   Count, PIndex) \
572
 
        _J2AI(Rc,(&(PArray)), Count, PIndex, Judy1SetArray, "Judy1SetArray")
573
 
#define J1U( Rc,    PArray,   Index) \
574
 
        _J1I(Rc, (&(PArray)), Index,  Judy1Unset, "Judy1Unset")
575
 
#define J1F( Rc,    PArray,   Index) \
576
 
        _J1I(Rc,    PArray, &(Index), Judy1First, "Judy1First")
577
 
#define J1N( Rc,    PArray,   Index) \
578
 
        _J1I(Rc,    PArray, &(Index), Judy1Next,  "Judy1Next")
579
 
#define J1L( Rc,    PArray,   Index) \
580
 
        _J1I(Rc,    PArray, &(Index), Judy1Last,  "Judy1Last")
581
 
#define J1P( Rc,    PArray,   Index) \
582
 
        _J1I(Rc,    PArray, &(Index), Judy1Prev,  "Judy1Prev")
583
 
#define J1FE(Rc,    PArray,   Index) \
584
 
        _J1I(Rc,    PArray, &(Index), Judy1FirstEmpty, "Judy1FirstEmpty")
585
 
#define J1NE(Rc,    PArray,   Index) \
586
 
        _J1I(Rc,    PArray, &(Index), Judy1NextEmpty,  "Judy1NextEmpty")
587
 
#define J1LE(Rc,    PArray,   Index) \
588
 
        _J1I(Rc,    PArray, &(Index), Judy1LastEmpty,  "Judy1LastEmpty")
589
 
#define J1PE(Rc,    PArray,   Index) \
590
 
        _J1I(Rc,    PArray, &(Index), Judy1PrevEmpty,  "Judy1PrevEmpty")
591
 
#define J1C( Rc,    PArray,   Index1,  Index2) \
592
 
        _J2C(Rc,    PArray,   Index1,  Index2, Judy1Count,   "Judy1Count")
593
 
#define J1BC(Rc,    PArray,   Count,   Index) \
594
 
        _J2I(Rc,    PArray,   Count, &(Index), Judy1ByCount, "Judy1ByCount")
595
 
#define J1FA(Rc,    PArray) \
596
 
        _J0I(Rc, (&(PArray)), Judy1FreeArray, "Judy1FreeArray")
597
 
#define J1MU(Rc,    PArray) \
598
 
        (Rc) = Judy1MemUsed(PArray)
599
 
 
600
 
#define JLG(PV,PArray,Index)                                            \
601
 
{                                                                       \
602
 
    Word_t  _jpt = ((Word_t) (PArray)) & JLAP_MASK;                     \
603
 
    PWord_t _PL  = (PWord_t) (((Word_t) (PArray)) ^ _jpt);              \
604
 
    extern const unsigned char __jL_LeafWOffset[];                      \
605
 
                                                                        \
606
 
    (PV) = (Pvoid_t) NULL;                                              \
607
 
                                                                        \
608
 
    if (_jpt == JLAPLEAF)                                               \
609
 
    {                                                                   \
610
 
        Word_t  _pop1 = _PL[0] + 1;                                     \
611
 
        if ((Index) <= _PL[_pop1])                                      \
612
 
        {                                                               \
613
 
            while (1)                                                   \
614
 
            {                                                           \
615
 
                if (*(++_PL) >= (Index))                                \
616
 
                {                                                       \
617
 
                    if (*_PL == (Index))                                \
618
 
                    {                                                   \
619
 
                        (PV) = (Pvoid_t)(_PL+__jL_LeafWOffset[_pop1]-1);\
620
 
                    }                                                   \
621
 
                    break;                                              \
622
 
                }                                                       \
623
 
            }                                                           \
624
 
        }                                                               \
625
 
    }                                                                   \
626
 
    else if (_jpt == JLAPBRANCH)                                        \
627
 
    {                                                                   \
628
 
        (PV) = (Pvoid_t) __JudyLGet((Pvoid_t) _PL, (Index));            \
629
 
    }                                                                   \
630
 
    else if (PArray != (Pvoid_t) NULL)                                  \
631
 
    {                                                                   \
632
 
        (PV) = PJERR;                                                   \
633
 
        _JSE("JudyLGet", JU_ERRNO_NOTJUDYL);                            \
634
 
    }                                                                   \
635
 
}
636
 
 
637
 
#define JLI( PV,    PArray,   Index) \
638
 
        _J1P(PV, (&(PArray)), Index,  JudyLIns,   "JudyLIns")
639
 
#define JLIA(Rc,    PArray,   Count, PIndex, PValue) \
640
 
        _J3AI(Rc,(&(PArray)), Count, PIndex, PValue, JudyLInsArray, \
641
 
                                                    "JudyLInsArray")
642
 
#define JLD( Rc,    PArray,   Index) \
643
 
        _J1I(Rc, (&(PArray)), Index,  JudyLDel,   "JudyLDel")
644
 
#define JLF( PV,    PArray,   Index) \
645
 
        _J1P(PV,    PArray, &(Index), JudyLFirst, "JudyLFirst")
646
 
 
647
 
#define JLN(PV,PArray,Index)                                            \
648
 
{                                                                       \
649
 
    Word_t  _jpt = ((Word_t) (PArray)) & JLAP_MASK;                     \
650
 
    PWord_t _PL  = (PWord_t) (((Word_t) (PArray)) ^ _jpt);              \
651
 
    extern const unsigned char __jL_LeafWOffset[];                      \
652
 
                                                                        \
653
 
    (PV) = (Pvoid_t) NULL;                                              \
654
 
                                                                        \
655
 
    if (_jpt == JLAPLEAF)                                               \
656
 
    {                                                                   \
657
 
        Word_t _pop1 = _PL[0] + 1;                                      \
658
 
        if ((Index) < _PL[_pop1])                                       \
659
 
        {                                                               \
660
 
            while (1)                                                   \
661
 
            {                                                           \
662
 
                if ((Index) < *(++_PL))                                 \
663
 
                {                                                       \
664
 
                    (Index) = *_PL;                                     \
665
 
                    (PV) = (Pvoid_t) (_PL + __jL_LeafWOffset[_pop1] -1);\
666
 
                    break;                                              \
667
 
                }                                                       \
668
 
            }                                                           \
669
 
        }                                                               \
670
 
    }                                                                   \
671
 
    else if (_jpt == JLAPBRANCH)                                        \
672
 
    {                                                                   \
673
 
        (PV) = (Pvoid_t) JudyLNext((Pvoid_t) PArray, &(Index), PJE0);   \
674
 
    }                                                                   \
675
 
    else if (PArray != (Pvoid_t) NULL)                                  \
676
 
    {                                                                   \
677
 
        (PV) = PJERR;                                                   \
678
 
        _JSE("JudyLNext", JU_ERRNO_NOTJUDYL);                           \
679
 
    }                                                                   \
680
 
}
681
 
 
682
 
#define JLL( PV,    PArray,   Index) \
683
 
        _J1P(PV,    PArray, &(Index), JudyLLast,  "JudyLLast")
684
 
#define JLP( PV,    PArray,   Index) \
685
 
        _J1P(PV,    PArray, &(Index), JudyLPrev,  "JudyLPrev")
686
 
#define JLFE(Rc,    PArray,   Index) \
687
 
        _J1I(Rc,    PArray, &(Index), JudyLFirstEmpty, "JudyLFirstEmpty")
688
 
#define JLNE(Rc,    PArray,   Index) \
689
 
        _J1I(Rc,    PArray, &(Index), JudyLNextEmpty,  "JudyLNextEmpty")
690
 
#define JLLE(Rc,    PArray,   Index) \
691
 
        _J1I(Rc,    PArray, &(Index), JudyLLastEmpty,  "JudyLLastEmpty")
692
 
#define JLPE(Rc,    PArray,   Index) \
693
 
        _J1I(Rc,    PArray, &(Index), JudyLPrevEmpty,  "JudyLPrevEmpty")
694
 
#define JLC( Rc,    PArray,   Index1,  Index2) \
695
 
        _J2C(Rc,    PArray,   Index1,  Index2, JudyLCount,   "JudyLCount")
696
 
#define JLBC(PV,    PArray,   Count,   Index) \
697
 
        _J2P(PV,    PArray,   Count, &(Index), JudyLByCount, "JudyLByCount")
698
 
#define JLFA(Rc,    PArray) \
699
 
        _J0I(Rc, (&(PArray)), JudyLFreeArray, "JudyLFreeArray")
700
 
#define JLMU(Rc,    PArray) \
701
 
        (Rc) = JudyLMemUsed(PArray)
702
 
 
703
 
#define JSLG( PV,    PArray,   Index) \
704
 
        _J1P( PV,    PArray,   Index, JudySLGet,   "JudySLGet")
705
 
#define JSLI( PV,    PArray,   Index) \
706
 
        _J1P( PV, (&(PArray)), Index, JudySLIns,   "JudySLIns")
707
 
#define JSLD( Rc,    PArray,   Index) \
708
 
        _J1I( Rc, (&(PArray)), Index, JudySLDel,   "JudySLDel")
709
 
#define JSLF( PV,    PArray,   Index) \
710
 
        _J1P( PV,    PArray,   Index, JudySLFirst, "JudySLFirst")
711
 
#define JSLN( PV,    PArray,   Index) \
712
 
        _J1P( PV,    PArray,   Index, JudySLNext,  "JudySLNext")
713
 
#define JSLL( PV,    PArray,   Index) \
714
 
        _J1P( PV,    PArray,   Index, JudySLLast,  "JudySLLast")
715
 
#define JSLP( PV,    PArray,   Index) \
716
 
        _J1P( PV,    PArray,   Index, JudySLPrev,  "JudySLPrev")
717
 
#define JSLFA(Rc,    PArray) \
718
 
        _J0I( Rc, (&(PArray)), JudySLFreeArray, "JudySLFreeArray")
 
522
// This is a slower version with current processors, but in the future...
 
523
#ifdef notdef
 
524
#define J1T(Rc,PArray,Index)                                    \
 
525
{                                                               \
 
526
    PWord_t P_L  = (PWord_t)(PArray);                           \
 
527
    (Rc) = 0;                                                   \
 
528
    if (P_L)                    /* cannot be a NULL pointer */  \
 
529
    {                                                           \
 
530
        if (P_L[0] < 31)        /* is a LeafL  */               \
 
531
        {                                                       \
 
532
            Word_t  _pop1 = P_L[0] + 1;                         \
 
533
            PWord_t P_LE  = P_L    + _pop1;                     \
 
534
            Word_t  _index = 0;                                 \
 
535
            int ii = 0;                                         \
 
536
            P_L++;                                              \
 
537
            while (_pop1 > 4)                                   \
 
538
            {                                                   \
 
539
                _pop1 /=2;                                      \
 
540
                _index = P_L[_pop1];                            \
 
541
                if ((Index) > _index) P_L += _pop1 + 1;         \
 
542
            }                                                   \
 
543
            while (P_L <= P_LE)                                 \
 
544
            {                                                   \
 
545
                ii++;                                           \
 
546
                _index = P_L[0];                                \
 
547
                if (_index >= (Index)) break;                   \
 
548
                P_L++;                                          \
 
549
            }                                                   \
 
550
            if (_index == (Index)) (Rc) = 1;                    \
 
551
        }                                                       \
 
552
        else                                                    \
 
553
        {                                                       \
 
554
            (Rc) = j__udy1Test((Pvoid_t)P_L, (Index));          \
 
555
        }                                                       \
 
556
    }                                                           \
 
557
}
 
558
#endif // notdef
 
559
 
 
560
#define J1T(Rc,PArray,Index)                                    \
 
561
{                                                               \
 
562
    PWord_t P_L  = (PWord_t)(PArray);                           \
 
563
    (Rc) = 0;                                                   \
 
564
    if (P_L)                    /* cannot be a NULL pointer */  \
 
565
    {                                                           \
 
566
        if (P_L[0] < 31)        /* is a LeafL  */               \
 
567
        {                                                       \
 
568
            Word_t  _pop1 = P_L[0] + 1;                         \
 
569
            Word_t  _EIndex = P_L[_pop1];                       \
 
570
            if (_pop1 >= 16)                                    \
 
571
            {                                                   \
 
572
                if ((Index) > P_L[_pop1/2]) P_L += _pop1/2;     \
 
573
            }                                                   \
 
574
            if ((Index) <= _EIndex)                             \
 
575
            {                                                   \
 
576
                while((Index) > *(++P_L));                      \
 
577
                if (*P_L == (Index)) (Rc) = 1;                  \
 
578
            }                                                   \
 
579
        }                                                       \
 
580
        else                                                    \
 
581
        {                                                       \
 
582
            (Rc) = j__udy1Test((Pvoid_t)P_L, Index);            \
 
583
        }                                                       \
 
584
    }                                                           \
 
585
}
 
586
 
 
587
#define J1S( Rc,    PArray,   Index) \
 
588
        J_1I(Rc, (&(PArray)), Index,  Judy1Set,   "Judy1Set")
 
589
#define J1SA(Rc,    PArray,   Count, PIndex) \
 
590
        J_2AI(Rc,(&(PArray)), Count, PIndex, Judy1SetArray, "Judy1SetArray")
 
591
#define J1U( Rc,    PArray,   Index) \
 
592
        J_1I(Rc, (&(PArray)), Index,  Judy1Unset, "Judy1Unset")
 
593
#define J1F( Rc,    PArray,   Index) \
 
594
        J_1I(Rc,    PArray, &(Index), Judy1First, "Judy1First")
 
595
#define J1N( Rc,    PArray,   Index) \
 
596
        J_1I(Rc,    PArray, &(Index), Judy1Next,  "Judy1Next")
 
597
#define J1L( Rc,    PArray,   Index) \
 
598
        J_1I(Rc,    PArray, &(Index), Judy1Last,  "Judy1Last")
 
599
#define J1P( Rc,    PArray,   Index) \
 
600
        J_1I(Rc,    PArray, &(Index), Judy1Prev,  "Judy1Prev")
 
601
#define J1FE(Rc,    PArray,   Index) \
 
602
        J_1I(Rc,    PArray, &(Index), Judy1FirstEmpty, "Judy1FirstEmpty")
 
603
#define J1NE(Rc,    PArray,   Index) \
 
604
        J_1I(Rc,    PArray, &(Index), Judy1NextEmpty,  "Judy1NextEmpty")
 
605
#define J1LE(Rc,    PArray,   Index) \
 
606
        J_1I(Rc,    PArray, &(Index), Judy1LastEmpty,  "Judy1LastEmpty")
 
607
#define J1PE(Rc,    PArray,   Index) \
 
608
        J_1I(Rc,    PArray, &(Index), Judy1PrevEmpty,  "Judy1PrevEmpty")
 
609
#define J1C( Rc,    PArray,   Index1,  Index2) \
 
610
        J_2C(Rc,    PArray,   Index1,  Index2, Judy1Count,   "Judy1Count")
 
611
#define J1BC(Rc,    PArray,   Count,   Index) \
 
612
        J_2I(Rc,    PArray,   Count, &(Index), Judy1ByCount, "Judy1ByCount")
 
613
#define J1FA(Rc,    PArray) \
 
614
        J_0I(Rc, (&(PArray)), Judy1FreeArray, "Judy1FreeArray")
 
615
#define J1MU(Rc,    PArray) \
 
616
        (Rc) = Judy1MemUsed(PArray)
 
617
 
 
618
#define JLG(PV,PArray,Index)                                    \
 
619
{                                                               \
 
620
    extern const uint8_t j__L_LeafWOffset[];                    \
 
621
    PWord_t P_L  = (PWord_t)(PArray);                           \
 
622
    (PV) = (Pvoid_t) NULL;                                      \
 
623
    if (P_L)                    /* cannot be a NULL pointer */  \
 
624
    {                                                           \
 
625
        if (P_L[0] < 31)        /* is a LeafL  */               \
 
626
        {                                                       \
 
627
            Word_t  _pop1 = P_L[0] + 1;                         \
 
628
            Word_t  _EIndex = P_L[_pop1];                       \
 
629
            Word_t  _off  = j__L_LeafWOffset[_pop1] - 1;        \
 
630
            if (_pop1 >= 16)                                    \
 
631
            {                                                   \
 
632
                if ((Index) > P_L[_pop1/2]) P_L += _pop1/2;     \
 
633
            }                                                   \
 
634
            if ((Index) <= _EIndex)                             \
 
635
            {                                                   \
 
636
                while((Index) > *(++P_L));                      \
 
637
                if (*P_L == (Index)) (PV) = (Pvoid_t)(P_L+_off);\
 
638
            }                                                   \
 
639
        }                                                       \
 
640
        else                                                    \
 
641
        {                                                       \
 
642
            (PV) = (Pvoid_t)j__udyLGet((Pvoid_t)P_L, Index);    \
 
643
        }                                                       \
 
644
    }                                                           \
 
645
}
 
646
 
 
647
#define JLI( PV,    PArray,   Index)                                    \
 
648
        J_1P(PV, (&(PArray)), Index,  JudyLIns,   "JudyLIns")
 
649
 
 
650
#define JLIA(Rc,    PArray,   Count, PIndex, PValue)                    \
 
651
        J_3AI(Rc,(&(PArray)), Count, PIndex, PValue, JudyLInsArray,     \
 
652
                                                  "JudyLInsArray")
 
653
#define JLD( Rc,    PArray,   Index)                                    \
 
654
        J_1I(Rc, (&(PArray)), Index,  JudyLDel,   "JudyLDel")
 
655
 
 
656
#define JLF( PV,    PArray,   Index)                                    \
 
657
        J_1P(PV,    PArray, &(Index), JudyLFirst, "JudyLFirst")
 
658
 
 
659
#define JLN(PV,PArray,Index)                                    \
 
660
{                                                               \
 
661
    extern const uint8_t j__L_LeafWOffset[];                    \
 
662
    PWord_t P_L  = (PWord_t) (PArray);                          \
 
663
                                                                \
 
664
    (PV) = (Pvoid_t) NULL;                                      \
 
665
                                                                \
 
666
    if (P_L)                    /* cannot be a NULL pointer */  \
 
667
    {                                                           \
 
668
        if (P_L[0] < 31)        /* is a LeafL  */               \
 
669
        {                                                       \
 
670
            Word_t _pop1 = P_L[0] + 1;                          \
 
671
            Word_t _off  = j__L_LeafWOffset[_pop1] -1;          \
 
672
            if ((Index) < P_L[_pop1])                           \
 
673
            {                                                   \
 
674
                while(1)                                        \
 
675
                {                                               \
 
676
                    if ((Index) < *(++P_L))                     \
 
677
                    {                                           \
 
678
                        (Index) = *P_L;                         \
 
679
                        (PV) = (Pvoid_t) (P_L + _off);          \
 
680
                        break;                                  \
 
681
                    }                                           \
 
682
                }                                               \
 
683
            }                                                   \
 
684
        }                                                       \
 
685
        else                                                    \
 
686
        {                                                       \
 
687
            (PV) = (Pvoid_t)JudyLNext((Pvoid_t) PArray, &(Index), PJE0); \
 
688
        }                                                       \
 
689
    }                                                           \
 
690
}
 
691
 
 
692
#define JLL( PV,    PArray,   Index)                                    \
 
693
        J_1P(PV,    PArray, &(Index), JudyLLast,  "JudyLLast")
 
694
#define JLP( PV,    PArray,   Index)                                    \
 
695
        J_1P(PV,    PArray, &(Index), JudyLPrev,  "JudyLPrev")
 
696
#define JLFE(Rc,    PArray,   Index)                                    \
 
697
        J_1I(Rc,    PArray, &(Index), JudyLFirstEmpty, "JudyLFirstEmpty")
 
698
#define JLNE(Rc,    PArray,   Index)                                    \
 
699
        J_1I(Rc,    PArray, &(Index), JudyLNextEmpty,  "JudyLNextEmpty")
 
700
#define JLLE(Rc,    PArray,   Index)                                    \
 
701
        J_1I(Rc,    PArray, &(Index), JudyLLastEmpty,  "JudyLLastEmpty")
 
702
#define JLPE(Rc,    PArray,   Index)                                    \
 
703
        J_1I(Rc,    PArray, &(Index), JudyLPrevEmpty,  "JudyLPrevEmpty")
 
704
#define JLC( Rc,    PArray,   Index1,  Index2)                          \
 
705
        J_2C(Rc,    PArray,   Index1,  Index2, JudyLCount,   "JudyLCount")
 
706
#define JLBC(PV,    PArray,   Count,   Index)                           \
 
707
        J_2P(PV,    PArray,   Count, &(Index), JudyLByCount, "JudyLByCount")
 
708
#define JLFA(Rc,    PArray)                                             \
 
709
        J_0I(Rc, (&(PArray)), JudyLFreeArray, "JudyLFreeArray")
 
710
#define JLMU(Rc,    PArray)                                             \
 
711
        (Rc) = JudyLMemUsed(PArray)
 
712
 
 
713
#define JHSI(PV,    PArray,   PIndex,   Count)                          \
 
714
        J_2P(PV, (&(PArray)), PIndex,   Count, JudyHSIns, "JudyHSIns")
 
715
#define JHSG(PV,    PArray,   PIndex,   Count)                          \
 
716
        (PV) = (Pvoid_t) JudyHSGet(PArray, PIndex, Count)
 
717
#define JHSD(Rc,    PArray,   PIndex,   Count)                          \
 
718
        J_2I(Rc, (&(PArray)), PIndex, Count, JudyHSDel, "JudyHSDel")
 
719
#define JHSFA(Rc,    PArray)                                            \
 
720
        J_0I(Rc, (&(PArray)), JudyHSFreeArray, "JudyHSFreeArray")
 
721
 
 
722
#define JSLG( PV,    PArray,   Index)                                   \
 
723
        J_1P( PV,    PArray,   Index, JudySLGet,   "JudySLGet")
 
724
#define JSLI( PV,    PArray,   Index)                                   \
 
725
        J_1P( PV, (&(PArray)), Index, JudySLIns,   "JudySLIns")
 
726
#define JSLD( Rc,    PArray,   Index)                                   \
 
727
        J_1I( Rc, (&(PArray)), Index, JudySLDel,   "JudySLDel")
 
728
#define JSLF( PV,    PArray,   Index)                                   \
 
729
        J_1P( PV,    PArray,   Index, JudySLFirst, "JudySLFirst")
 
730
#define JSLN( PV,    PArray,   Index)                                   \
 
731
        J_1P( PV,    PArray,   Index, JudySLNext,  "JudySLNext")
 
732
#define JSLL( PV,    PArray,   Index)                                   \
 
733
        J_1P( PV,    PArray,   Index, JudySLLast,  "JudySLLast")
 
734
#define JSLP( PV,    PArray,   Index)                                   \
 
735
        J_1P( PV,    PArray,   Index, JudySLPrev,  "JudySLPrev")
 
736
#define JSLFA(Rc,    PArray)                                            \
 
737
        J_0I( Rc, (&(PArray)), JudySLFreeArray, "JudySLFreeArray")
719
738
 
720
739
#ifdef __cplusplus
721
740
}