| 1 | // Copyright (C) 2000 - 2002 Hewlett-Packard Company |
| 2 | // |
| 3 | // This program is free software; you can redistribute it and/or modify it |
| 4 | // under the term of the GNU Lesser General Public License as published by the |
| 5 | // Free Software Foundation; either version 2 of the License, or (at your |
| 6 | // option) any later version. |
| 7 | // |
| 8 | // This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 11 | // for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU Lesser General Public License |
| 14 | // along with this program; if not, write to the Free Software Foundation, |
| 15 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | // _________________ |
| 17 | |
| 18 | // @(#) $Revision: 4.12 $ $Source: /judy/src/JudyCommon/JudyFirst.c $ |
| 19 | // |
| 20 | // Judy*First[Empty]() and Judy*Last[Empty]() routines for Judy1 and JudyL. |
| 21 | // Compile with one of -DJUDY1 or -DJUDYL. |
| 22 | // |
| 23 | // These are inclusive versions of Judy*Next[Empty]() and Judy*Prev[Empty](). |
| 24 | |
| 25 | #if (! (defined(JUDY1) || defined(JUDYL))) |
| 26 | #error: One of -DJUDY1 or -DJUDYL must be specified. |
| 27 | #endif |
| 28 | |
| 29 | #ifdef JUDY1 |
| 30 | #include "Judy1.h" |
| 31 | #else |
| 32 | #include "JudyL.h" |
| 33 | #endif |
| 34 | |
| 35 | |
| 36 | // **************************************************************************** |
| 37 | // J U D Y 1 F I R S T |
| 38 | // J U D Y L F I R S T |
| 39 | // |
| 40 | // See the manual entry for details. |
| 41 | |
| 42 | #ifdef JUDY1 |
| 43 | FUNCTION int Judy1First |
| 44 | #else |
| 45 | FUNCTION PPvoid_t JudyLFirst |
| 46 | #endif |
| 47 | ( |
| 48 | Pcvoid_t PArray, // Judy array to search. |
| 49 | Word_t * PIndex, // starting point and result. |
| 50 | PJError_t PJError // optional, for returning error info. |
| 51 | ) |
| 52 | { |
| 53 | if (PIndex == (PWord_t) NULL) // caller error: |
| 54 | { |
| 55 | JU_SET_ERRNO(PJError, JU_ERRNO_NULLPINDEX); |
| 56 | JUDY1CODE(return(JERRI );) |
| 57 | JUDYLCODE(return(PPJERR);) |
| 58 | } |
| 59 | |
| 60 | #ifdef JUDY1 |
| 61 | switch (Judy1Test(PArray, *PIndex, PJError)) |
| 62 | { |
| 63 | case 1: return(1); // found *PIndex itself. |
| 64 | case 0: return(Judy1Next(PArray, PIndex, PJError)); |
| 65 | default: return(JERRI); |
| 66 | } |
| 67 | #else |
| 68 | { |
| 69 | PPvoid_t PValue; |
| 70 | |
| 71 | if ((PValue = JudyLGet(PArray, *PIndex, PJError)) == PPJERR) |
| 72 | return(PPJERR); |
| 73 | |
| 74 | if (PValue != (PPvoid_t) NULL) return(PValue); // found *PIndex. |
| 75 | |
| 76 | return(JudyLNext(PArray, PIndex, PJError)); |
| 77 | } |
| 78 | #endif |
| 79 | |
| 80 | } // Judy1First() / JudyLFirst() |
| 81 | |
| 82 | |
| 83 | // **************************************************************************** |
| 84 | // J U D Y 1 L A S T |
| 85 | // J U D Y L L A S T |
| 86 | // |
| 87 | // See the manual entry for details. |
| 88 | |
| 89 | #ifdef JUDY1 |
| 90 | FUNCTION int Judy1Last( |
| 91 | #else |
| 92 | FUNCTION PPvoid_t JudyLLast( |
| 93 | #endif |
| 94 | Pcvoid_t PArray, // Judy array to search. |
| 95 | Word_t * PIndex, // starting point and result. |
| 96 | PJError_t PJError) // optional, for returning error info. |
| 97 | { |
| 98 | if (PIndex == (PWord_t) NULL) |
| 99 | { |
| 100 | JU_SET_ERRNO(PJError, JU_ERRNO_NULLPINDEX); // caller error. |
| 101 | JUDY1CODE(return(JERRI );) |
| 102 | JUDYLCODE(return(PPJERR);) |
| 103 | } |
| 104 | |
| 105 | #ifdef JUDY1 |
| 106 | switch (Judy1Test(PArray, *PIndex, PJError)) |
| 107 | { |
| 108 | case 1: return(1); // found *PIndex itself. |
| 109 | case 0: return(Judy1Prev(PArray, PIndex, PJError)); |
| 110 | default: return(JERRI); |
| 111 | } |
| 112 | #else |
| 113 | { |
| 114 | PPvoid_t PValue; |
| 115 | |
| 116 | if ((PValue = JudyLGet(PArray, *PIndex, PJError)) == PPJERR) |
| 117 | return(PPJERR); |
| 118 | |
| 119 | if (PValue != (PPvoid_t) NULL) return(PValue); // found *PIndex. |
| 120 | |
| 121 | return(JudyLPrev(PArray, PIndex, PJError)); |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | } // Judy1Last() / JudyLLast() |
| 126 | |
| 127 | |
| 128 | // **************************************************************************** |
| 129 | // J U D Y 1 F I R S T E M P T Y |
| 130 | // J U D Y L F I R S T E M P T Y |
| 131 | // |
| 132 | // See the manual entry for details. |
| 133 | |
| 134 | #ifdef JUDY1 |
| 135 | FUNCTION int Judy1FirstEmpty( |
| 136 | #else |
| 137 | FUNCTION int JudyLFirstEmpty( |
| 138 | #endif |
| 139 | Pcvoid_t PArray, // Judy array to search. |
| 140 | Word_t * PIndex, // starting point and result. |
| 141 | PJError_t PJError) // optional, for returning error info. |
| 142 | { |
| 143 | if (PIndex == (PWord_t) NULL) // caller error: |
| 144 | { |
| 145 | JU_SET_ERRNO(PJError, JU_ERRNO_NULLPINDEX); |
| 146 | return(JERRI); |
| 147 | } |
| 148 | |
| 149 | #ifdef JUDY1 |
| 150 | switch (Judy1Test(PArray, *PIndex, PJError)) |
| 151 | { |
| 152 | case 0: return(1); // found *PIndex itself. |
| 153 | case 1: return(Judy1NextEmpty(PArray, PIndex, PJError)); |
| 154 | default: return(JERRI); |
| 155 | } |
| 156 | #else |
| 157 | { |
| 158 | PPvoid_t PValue; |
| 159 | |
| 160 | if ((PValue = JudyLGet(PArray, *PIndex, PJError)) == PPJERR) |
| 161 | return(JERRI); |
| 162 | |
| 163 | if (PValue == (PPvoid_t) NULL) return(1); // found *PIndex. |
| 164 | |
| 165 | return(JudyLNextEmpty(PArray, PIndex, PJError)); |
| 166 | } |
| 167 | #endif |
| 168 | |
| 169 | } // Judy1FirstEmpty() / JudyLFirstEmpty() |
| 170 | |
| 171 | |
| 172 | // **************************************************************************** |
| 173 | // J U D Y 1 L A S T E M P T Y |
| 174 | // J U D Y L L A S T E M P T Y |
| 175 | // |
| 176 | // See the manual entry for details. |
| 177 | |
| 178 | #ifdef JUDY1 |
| 179 | FUNCTION int Judy1LastEmpty( |
| 180 | #else |
| 181 | FUNCTION int JudyLLastEmpty( |
| 182 | #endif |
| 183 | Pcvoid_t PArray, // Judy array to search. |
| 184 | Word_t * PIndex, // starting point and result. |
| 185 | PJError_t PJError) // optional, for returning error info. |
| 186 | { |
| 187 | if (PIndex == (PWord_t) NULL) |
| 188 | { |
| 189 | JU_SET_ERRNO(PJError, JU_ERRNO_NULLPINDEX); // caller error. |
| 190 | return(JERRI); |
| 191 | } |
| 192 | |
| 193 | #ifdef JUDY1 |
| 194 | switch (Judy1Test(PArray, *PIndex, PJError)) |
| 195 | { |
| 196 | case 0: return(1); // found *PIndex itself. |
| 197 | case 1: return(Judy1PrevEmpty(PArray, PIndex, PJError)); |
| 198 | default: return(JERRI); |
| 199 | } |
| 200 | #else |
| 201 | { |
| 202 | PPvoid_t PValue; |
| 203 | |
| 204 | if ((PValue = JudyLGet(PArray, *PIndex, PJError)) == PPJERR) |
| 205 | return(JERRI); |
| 206 | |
| 207 | if (PValue == (PPvoid_t) NULL) return(1); // found *PIndex. |
| 208 | |
| 209 | return(JudyLPrevEmpty(PArray, PIndex, PJError)); |
| 210 | } |
| 211 | #endif |
| 212 | |
| 213 | } // Judy1LastEmpty() / JudyLLastEmpty() |