| 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.25 $ $Source: /judy/src/JudyCommon/JudyDecascade.c $ |
| 19 | // |
| 20 | // "Decascade" support functions for JudyDel.c: These functions convert |
| 21 | // smaller-index-size leaves to larger-index-size leaves, and also, bitmap |
| 22 | // leaves (LeafB1s) to Leaf1s, and some types of branches to smaller branches |
| 23 | // at the same index size. Some "decascading" occurs explicitly in JudyDel.c, |
| 24 | // but rare or large subroutines appear as functions here, and the overhead to |
| 25 | // call them is negligible. |
| 26 | // |
| 27 | // Compile with one of -DJUDY1 or -DJUDYL. Note: Function names are converted |
| 28 | // to Judy1 or JudyL specific values by external #defines. |
| 29 | |
| 30 | #if (! (defined(JUDY1) || defined(JUDYL))) |
| 31 | #error: One of -DJUDY1 or -DJUDYL must be specified. |
| 32 | #endif |
| 33 | |
| 34 | #ifdef JUDY1 |
| 35 | #include "Judy1.h" |
| 36 | #endif |
| 37 | #ifdef JUDYL |
| 38 | #include "JudyL.h" |
| 39 | #endif |
| 40 | |
| 41 | #include "JudyPrivate1L.h" |
| 42 | |
| 43 | DBGCODE(extern void JudyCheckSorted(Pjll_t Pjll, Word_t Pop1, long IndexSize);) |
| 44 | |
| 45 | |
| 46 | // **************************************************************************** |
| 47 | // __ J U D Y C O P Y 2 T O 3 |
| 48 | // |
| 49 | // Copy one or more 2-byte Indexes to a series of 3-byte Indexes. |
| 50 | |
| 51 | FUNCTION static void j__udyCopy2to3( |
| 52 | uint8_t * PDest, // to where to copy 3-byte Indexes. |
| 53 | uint16_t * PSrc, // from where to copy 2-byte indexes. |
| 54 | Word_t Pop1, // number of Indexes to copy. |
| 55 | Word_t MSByte) // most-significant byte, prefix to each Index. |
| 56 | { |
| 57 | Word_t Temp; // for building 3-byte Index. |
| 58 | |
| 59 | assert(Pop1); |
| 60 | |
| 61 | do { |
| 62 | Temp = MSByte | *PSrc++; |
| 63 | JU_COPY3_LONG_TO_PINDEX(PDest, Temp); |
| 64 | PDest += 3; |
| 65 | } while (--Pop1); |
| 66 | |
| 67 | } // j__udyCopy2to3() |
| 68 | |
| 69 | |
| 70 | #ifdef JU_64BIT |
| 71 | |
| 72 | // **************************************************************************** |
| 73 | // __ J U D Y C O P Y 3 T O 4 |
| 74 | // |
| 75 | // Copy one or more 3-byte Indexes to a series of 4-byte Indexes. |
| 76 | |
| 77 | FUNCTION static void j__udyCopy3to4( |
| 78 | uint32_t * PDest, // to where to copy 4-byte Indexes. |
| 79 | uint8_t * PSrc, // from where to copy 3-byte indexes. |
| 80 | Word_t Pop1, // number of Indexes to copy. |
| 81 | Word_t MSByte) // most-significant byte, prefix to each Index. |
| 82 | { |
| 83 | Word_t Temp; // for building 4-byte Index. |
| 84 | |
| 85 | assert(Pop1); |
| 86 | |
| 87 | do { |
| 88 | JU_COPY3_PINDEX_TO_LONG(Temp, PSrc); |
| 89 | Temp |= MSByte; |
| 90 | PSrc += 3; |
| 91 | *PDest++ = Temp; // truncates to uint32_t. |
| 92 | } while (--Pop1); |
| 93 | |
| 94 | } // j__udyCopy3to4() |
| 95 | |
| 96 | |
| 97 | // **************************************************************************** |
| 98 | // __ J U D Y C O P Y 4 T O 5 |
| 99 | // |
| 100 | // Copy one or more 4-byte Indexes to a series of 5-byte Indexes. |
| 101 | |
| 102 | FUNCTION static void j__udyCopy4to5( |
| 103 | uint8_t * PDest, // to where to copy 4-byte Indexes. |
| 104 | uint32_t * PSrc, // from where to copy 4-byte indexes. |
| 105 | Word_t Pop1, // number of Indexes to copy. |
| 106 | Word_t MSByte) // most-significant byte, prefix to each Index. |
| 107 | { |
| 108 | Word_t Temp; // for building 5-byte Index. |
| 109 | |
| 110 | assert(Pop1); |
| 111 | |
| 112 | do { |
| 113 | Temp = MSByte | *PSrc++; |
| 114 | JU_COPY5_LONG_TO_PINDEX(PDest, Temp); |
| 115 | PDest += 5; |
| 116 | } while (--Pop1); |
| 117 | |
| 118 | } // j__udyCopy4to5() |
| 119 | |
| 120 | |
| 121 | // **************************************************************************** |
| 122 | // __ J U D Y C O P Y 5 T O 6 |
| 123 | // |
| 124 | // Copy one or more 5-byte Indexes to a series of 6-byte Indexes. |
| 125 | |
| 126 | FUNCTION static void j__udyCopy5to6( |
| 127 | uint8_t * PDest, // to where to copy 6-byte Indexes. |
| 128 | uint8_t * PSrc, // from where to copy 5-byte indexes. |
| 129 | Word_t Pop1, // number of Indexes to copy. |
| 130 | Word_t MSByte) // most-significant byte, prefix to each Index. |
| 131 | { |
| 132 | Word_t Temp; // for building 6-byte Index. |
| 133 | |
| 134 | assert(Pop1); |
| 135 | |
| 136 | do { |
| 137 | JU_COPY5_PINDEX_TO_LONG(Temp, PSrc); |
| 138 | Temp |= MSByte; |
| 139 | JU_COPY6_LONG_TO_PINDEX(PDest, Temp); |
| 140 | PSrc += 5; |
| 141 | PDest += 6; |
| 142 | } while (--Pop1); |
| 143 | |
| 144 | } // j__udyCopy5to6() |
| 145 | |
| 146 | |
| 147 | // **************************************************************************** |
| 148 | // __ J U D Y C O P Y 6 T O 7 |
| 149 | // |
| 150 | // Copy one or more 6-byte Indexes to a series of 7-byte Indexes. |
| 151 | |
| 152 | FUNCTION static void j__udyCopy6to7( |
| 153 | uint8_t * PDest, // to where to copy 6-byte Indexes. |
| 154 | uint8_t * PSrc, // from where to copy 5-byte indexes. |
| 155 | Word_t Pop1, // number of Indexes to copy. |
| 156 | Word_t MSByte) // most-significant byte, prefix to each Index. |
| 157 | { |
| 158 | Word_t Temp; // for building 6-byte Index. |
| 159 | |
| 160 | assert(Pop1); |
| 161 | |
| 162 | do { |
| 163 | JU_COPY6_PINDEX_TO_LONG(Temp, PSrc); |
| 164 | Temp |= MSByte; |
| 165 | JU_COPY7_LONG_TO_PINDEX(PDest, Temp); |
| 166 | PSrc += 6; |
| 167 | PDest += 7; |
| 168 | } while (--Pop1); |
| 169 | |
| 170 | } // j__udyCopy6to7() |
| 171 | |
| 172 | #endif // JU_64BIT |
| 173 | |
| 174 | |
| 175 | #ifndef JU_64BIT // 32-bit |
| 176 | |
| 177 | // **************************************************************************** |
| 178 | // __ J U D Y C O P Y 3 T O W |
| 179 | // |
| 180 | // Copy one or more 3-byte Indexes to a series of longs (words, always 4-byte). |
| 181 | |
| 182 | FUNCTION static void j__udyCopy3toW( |
| 183 | PWord_t PDest, // to where to copy full-word Indexes. |
| 184 | uint8_t * PSrc, // from where to copy 3-byte indexes. |
| 185 | Word_t Pop1, // number of Indexes to copy. |
| 186 | Word_t MSByte) // most-significant byte, prefix to each Index. |
| 187 | { |
| 188 | assert(Pop1); |
| 189 | |
| 190 | do { |
| 191 | JU_COPY3_PINDEX_TO_LONG(*PDest, PSrc); |
| 192 | *PDest++ |= MSByte; |
| 193 | PSrc += 3; |
| 194 | } while (--Pop1); |
| 195 | |
| 196 | } // j__udyCopy3toW() |
| 197 | |
| 198 | |
| 199 | #else // JU_64BIT |
| 200 | |
| 201 | // **************************************************************************** |
| 202 | // __ J U D Y C O P Y 7 T O W |
| 203 | // |
| 204 | // Copy one or more 7-byte Indexes to a series of longs (words, always 8-byte). |
| 205 | |
| 206 | FUNCTION static void j__udyCopy7toW( |
| 207 | PWord_t PDest, // to where to copy full-word Indexes. |
| 208 | uint8_t * PSrc, // from where to copy 7-byte indexes. |
| 209 | Word_t Pop1, // number of Indexes to copy. |
| 210 | Word_t MSByte) // most-significant byte, prefix to each Index. |
| 211 | { |
| 212 | assert(Pop1); |
| 213 | |
| 214 | do { |
| 215 | JU_COPY7_PINDEX_TO_LONG(*PDest, PSrc); |
| 216 | *PDest++ |= MSByte; |
| 217 | PSrc += 7; |
| 218 | } while (--Pop1); |
| 219 | |
| 220 | } // j__udyCopy7toW() |
| 221 | |
| 222 | #endif // JU_64BIT |
| 223 | |
| 224 | |
| 225 | // **************************************************************************** |
| 226 | // __ J U D Y B R A N C H B T O B R A N C H L |
| 227 | // |
| 228 | // When a BranchB shrinks to have few enough JPs, call this function to convert |
| 229 | // it to a BranchL. Return 1 for success, or -1 for failure (with details in |
| 230 | // Pjpm). |
| 231 | |
| 232 | FUNCTION int j__udyBranchBToBranchL( |
| 233 | Pjp_t Pjp, // points to BranchB to shrink. |
| 234 | Pvoid_t Pjpm) // for global accounting. |
| 235 | { |
| 236 | Pjbb_t PjbbRaw; // old BranchB to shrink. |
| 237 | Pjbb_t Pjbb; |
| 238 | Pjbl_t PjblRaw; // new BranchL to create. |
| 239 | Pjbl_t Pjbl; |
| 240 | Word_t Digit; // in BranchB. |
| 241 | Word_t NumJPs; // non-null JPs in BranchB. |
| 242 | uint8_t Expanse[cJU_BRANCHLMAXJPS]; // for building jbl_Expanse[]. |
| 243 | Pjp_t Pjpjbl; // current JP in BranchL. |
| 244 | Word_t SubExp; // in BranchB. |
| 245 | |
| 246 | assert(JU_JPTYPE(Pjp) >= cJU_JPBRANCH_B2); |
| 247 | assert(JU_JPTYPE(Pjp) <= cJU_JPBRANCH_B); |
| 248 | |
| 249 | PjbbRaw = (Pjbb_t) (Pjp->jp_Addr); |
| 250 | Pjbb = P_JBB(PjbbRaw); |
| 251 | |
| 252 | // Copy 1-byte subexpanse digits from BranchB to temporary buffer for BranchL, |
| 253 | // for each bit set in the BranchB: |
| 254 | // |
| 255 | // TBD: The following supports variable-sized linear branches, but they are no |
| 256 | // longer variable; this could be simplified to save the copying. |
| 257 | // |
| 258 | // TBD: Since cJU_BRANCHLMAXJP == 7 now, and cJU_BRANCHUNUMJPS == 256, the |
| 259 | // following might be inefficient; is there a faster way to do it? At least |
| 260 | // skip wholly empty subexpanses? |
| 261 | |
| 262 | for (NumJPs = Digit = 0; Digit < cJU_BRANCHUNUMJPS; ++Digit) |
| 263 | { |
| 264 | if (JU_BITMAPTESTB(Pjbb, Digit)) |
| 265 | { |
| 266 | Expanse[NumJPs++] = Digit; |
| 267 | assert(NumJPs <= cJU_BRANCHLMAXJPS); // required of caller. |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Allocate and populate the BranchL: |
| 272 | |
| 273 | if ((PjblRaw = j__udyAllocJBL(Pjpm)) == (Pjbl_t) NULL) return(-1); |
| 274 | Pjbl = P_JBL(PjblRaw); |
| 275 | |
| 276 | JU_COPYMEM(Pjbl->jbl_Expanse, Expanse, NumJPs); |
| 277 | |
| 278 | Pjbl->jbl_NumJPs = NumJPs; |
| 279 | DBGCODE(JudyCheckSorted((Pjll_t) (Pjbl->jbl_Expanse), NumJPs, 1);) |
| 280 | |
| 281 | // Copy JPs from each BranchB subexpanse subarray: |
| 282 | |
| 283 | Pjpjbl = P_JP(Pjbl->jbl_jp); // start at first JP in array. |
| 284 | |
| 285 | for (SubExp = 0; SubExp < cJU_NUMSUBEXPB; ++SubExp) |
| 286 | { |
| 287 | Pjp_t PjpRaw = JU_JBB_PJP(Pjbb, SubExp); // current Pjp. |
| 288 | Pjp_t Pjp; |
| 289 | |
| 290 | if (PjpRaw == (Pjp_t) NULL) continue; // skip empty subexpanse. |
| 291 | Pjp = P_JP(PjpRaw); |
| 292 | |
| 293 | NumJPs = j__udyCountBitsB(JU_JBB_BITMAP(Pjbb, SubExp)); |
| 294 | assert(NumJPs); |
| 295 | JU_COPYMEM(Pjpjbl, Pjp, NumJPs); // one subarray at a time. |
| 296 | |
| 297 | Pjpjbl += NumJPs; |
| 298 | j__udyFreeJBBJP(PjpRaw, NumJPs, Pjpm); // subarray. |
| 299 | } |
| 300 | j__udyFreeJBB(PjbbRaw, Pjpm); // BranchB itself. |
| 301 | |
| 302 | // Finish up: Calculate new JP type (same index size = level in new class), |
| 303 | // and tie new BranchB into parent JP: |
| 304 | |
| 305 | Pjp->jp_Type += cJU_JPBRANCH_L - cJU_JPBRANCH_B; |
| 306 | Pjp->jp_Addr = (Word_t) PjblRaw; |
| 307 | |
| 308 | return(1); |
| 309 | |
| 310 | } // j__udyBranchBToBranchL() |
| 311 | |
| 312 | |
| 313 | #ifdef notdef |
| 314 | |
| 315 | // **************************************************************************** |
| 316 | // __ J U D Y B R A N C H U T O B R A N C H B |
| 317 | // |
| 318 | // When a BranchU shrinks to need little enough memory, call this function to |
| 319 | // convert it to a BranchB to save memory (at the cost of some speed). Return |
| 320 | // 1 for success, or -1 for failure (with details in Pjpm). |
| 321 | // |
| 322 | // TBD: Fill out if/when needed. Not currently used in JudyDel.c for reasons |
| 323 | // explained there. |
| 324 | |
| 325 | FUNCTION int j__udyBranchUToBranchB( |
| 326 | Pjp_t Pjp, // points to BranchU to shrink. |
| 327 | Pvoid_t Pjpm) // for global accounting. |
| 328 | { |
| 329 | assert(FALSE); |
| 330 | return(1); |
| 331 | } |
| 332 | #endif // notdef |
| 333 | |
| 334 | |
| 335 | #if (defined(JUDYL) || (! defined(JU_64BIT))) |
| 336 | |
| 337 | // **************************************************************************** |
| 338 | // __ J U D Y L E A F B 1 T O L E A F 1 |
| 339 | // |
| 340 | // Shrink a bitmap leaf (cJU_LEAFB1) to linear leaf (cJU_JPLEAF1). |
| 341 | // Return 1 for success, or -1 for failure (with details in Pjpm). |
| 342 | // |
| 343 | // Note: This function is different than the other JudyLeaf*ToLeaf*() |
| 344 | // functions because it receives a Pjp, not just a leaf, and handles its own |
| 345 | // allocation and free, in order to allow the caller to continue with a LeafB1 |
| 346 | // if allocation fails. |
| 347 | |
| 348 | FUNCTION int j__udyLeafB1ToLeaf1( |
| 349 | Pjp_t Pjp, // points to LeafB1 to shrink. |
| 350 | Pvoid_t Pjpm) // for global accounting. |
| 351 | { |
| 352 | Pjlb_t PjlbRaw; // bitmap in old leaf. |
| 353 | Pjlb_t Pjlb; |
| 354 | Pjll_t PjllRaw; // new Leaf1. |
| 355 | uint8_t * Pleaf1; // Leaf1 pointer type. |
| 356 | Word_t Digit; // in LeafB1 bitmap. |
| 357 | #ifdef JUDYL |
| 358 | Pjv_t PjvNew; // value area in new Leaf1. |
| 359 | Word_t Pop1; |
| 360 | Word_t SubExp; |
| 361 | #endif |
| 362 | |
| 363 | assert(JU_JPTYPE(Pjp) == cJU_JPLEAF_B1); |
| 364 | assert(((JU_JPDCDPOP0(Pjp) & 0xFF) + 1) == cJU_LEAF1_MAXPOP1); |
| 365 | |
| 366 | // Allocate JPLEAF1 and prepare pointers: |
| 367 | |
| 368 | if ((PjllRaw = j__udyAllocJLL1(cJU_LEAF1_MAXPOP1, Pjpm)) == 0) |
| 369 | return(-1); |
| 370 | |
| 371 | Pleaf1 = (uint8_t *) P_JLL(PjllRaw); |
| 372 | PjlbRaw = (Pjlb_t) (Pjp->jp_Addr); |
| 373 | Pjlb = P_JLB(PjlbRaw); |
| 374 | JUDYLCODE(PjvNew = JL_LEAF1VALUEAREA(Pleaf1, cJL_LEAF1_MAXPOP1);) |
| 375 | |
| 376 | // Copy 1-byte indexes from old LeafB1 to new Leaf1: |
| 377 | |
| 378 | for (Digit = 0; Digit < cJU_BRANCHUNUMJPS; ++Digit) |
| 379 | if (JU_BITMAPTESTL(Pjlb, Digit)) |
| 380 | *Pleaf1++ = Digit; |
| 381 | |
| 382 | #ifdef JUDYL |
| 383 | |
| 384 | // Copy all old-LeafB1 value areas from value subarrays to new Leaf1: |
| 385 | |
| 386 | for (SubExp = 0; SubExp < cJU_NUMSUBEXPL; ++SubExp) |
| 387 | { |
| 388 | Pjv_t PjvRaw = JL_JLB_PVALUE(Pjlb, SubExp); |
| 389 | Pjv_t Pjv = P_JV(PjvRaw); |
| 390 | |
| 391 | if (Pjv == (Pjv_t) NULL) continue; // skip empty subarray. |
| 392 | |
| 393 | Pop1 = j__udyCountBitsL(JU_JLB_BITMAP(Pjlb, SubExp)); // subarray. |
| 394 | assert(Pop1); |
| 395 | |
| 396 | JU_COPYMEM(PjvNew, Pjv, Pop1); // copy value areas. |
| 397 | j__udyLFreeJV(PjvRaw, Pop1, Pjpm); |
| 398 | PjvNew += Pop1; // advance through new. |
| 399 | } |
| 400 | |
| 401 | assert((((Word_t) Pleaf1) - (Word_t) P_JLL(PjllRaw)) |
| 402 | == (PjvNew - JL_LEAF1VALUEAREA(P_JLL(PjllRaw), cJL_LEAF1_MAXPOP1))); |
| 403 | #endif // JUDYL |
| 404 | |
| 405 | DBGCODE(JudyCheckSorted((Pjll_t) P_JLL(PjllRaw), |
| 406 | (((Word_t) Pleaf1) - (Word_t) P_JLL(PjllRaw)), 1);) |
| 407 | |
| 408 | // Finish up: Free the old LeafB1 and plug the new Leaf1 into the JP: |
| 409 | // |
| 410 | // Note: jp_DcdPopO does not change here. |
| 411 | |
| 412 | j__udyFreeJLB1(PjlbRaw, Pjpm); |
| 413 | |
| 414 | Pjp->jp_Addr = (Word_t) PjllRaw; |
| 415 | Pjp->jp_Type = cJU_JPLEAF1; |
| 416 | |
| 417 | return(1); |
| 418 | |
| 419 | } // j__udyLeafB1ToLeaf1() |
| 420 | |
| 421 | #endif // (JUDYL || (! JU_64BIT)) |
| 422 | |
| 423 | |
| 424 | // **************************************************************************** |
| 425 | // __ J U D Y L E A F 1 T O L E A F 2 |
| 426 | // |
| 427 | // Copy 1-byte Indexes from a LeafB1 or Leaf1 to 2-byte Indexes in a Leaf2. |
| 428 | // Pjp MUST be one of: cJU_JPLEAF_B1, cJU_JPLEAF1, or cJU_JPIMMED_1_*. |
| 429 | // Return number of Indexes copied. |
| 430 | // |
| 431 | // TBD: In this and all following functions, the caller should already be able |
| 432 | // to compute the Pop1 return value, so why return it? |
| 433 | |
| 434 | FUNCTION Word_t j__udyLeaf1ToLeaf2( |
| 435 | uint16_t * PLeaf2, // destination uint16_t * Index portion of leaf. |
| 436 | #ifdef JUDYL |
| 437 | Pjv_t Pjv2, // destination value part of leaf. |
| 438 | #endif |
| 439 | Pjp_t Pjp, // 1-byte-index object from which to copy. |
| 440 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 441 | Pvoid_t Pjpm) // for global accounting. |
| 442 | { |
| 443 | Word_t Pop1; // Indexes in leaf. |
| 444 | Word_t Offset; // in linear leaf list. |
| 445 | JUDYLCODE(Pjv_t Pjv1Raw;) // source object value area. |
| 446 | JUDYLCODE(Pjv_t Pjv1;) |
| 447 | |
| 448 | switch (JU_JPTYPE(Pjp)) |
| 449 | { |
| 450 | |
| 451 | |
| 452 | // JPLEAF_B1: |
| 453 | |
| 454 | case cJU_JPLEAF_B1: |
| 455 | { |
| 456 | Pjlb_t Pjlb = P_JLB(Pjp->jp_Addr); |
| 457 | Word_t Digit; // in LeafB1 bitmap. |
| 458 | JUDYLCODE(Word_t SubExp;) // in LeafB1. |
| 459 | |
| 460 | Pop1 = JU_JPBRANCH_POP0(Pjp, 1) + 1; assert(Pop1); |
| 461 | |
| 462 | // Copy 1-byte indexes from old LeafB1 to new Leaf2, including splicing in |
| 463 | // the missing MSByte needed in the Leaf2: |
| 464 | |
| 465 | for (Digit = 0; Digit < cJU_BRANCHUNUMJPS; ++Digit) |
| 466 | if (JU_BITMAPTESTL(Pjlb, Digit)) |
| 467 | *PLeaf2++ = MSByte | Digit; |
| 468 | |
| 469 | #ifdef JUDYL |
| 470 | |
| 471 | // Copy all old-LeafB1 value areas from value subarrays to new Leaf2: |
| 472 | |
| 473 | for (SubExp = 0; SubExp < cJU_NUMSUBEXPL; ++SubExp) |
| 474 | { |
| 475 | Word_t SubExpPop1; |
| 476 | |
| 477 | Pjv1Raw = JL_JLB_PVALUE(Pjlb, SubExp); |
| 478 | if (Pjv1Raw == (Pjv_t) NULL) continue; // skip empty. |
| 479 | Pjv1 = P_JV(Pjv1Raw); |
| 480 | |
| 481 | SubExpPop1 = j__udyCountBitsL(JU_JLB_BITMAP(Pjlb, SubExp)); |
| 482 | assert(SubExpPop1); |
| 483 | |
| 484 | JU_COPYMEM(Pjv2, Pjv1, SubExpPop1); // copy value areas. |
| 485 | j__udyLFreeJV(Pjv1Raw, SubExpPop1, Pjpm); |
| 486 | Pjv2 += SubExpPop1; // advance through new. |
| 487 | } |
| 488 | #endif // JUDYL |
| 489 | |
| 490 | j__udyFreeJLB1((Pjlb_t) (Pjp->jp_Addr), Pjpm); // LeafB1 itself. |
| 491 | return(Pop1); |
| 492 | |
| 493 | } // case cJU_JPLEAF_B1 |
| 494 | |
| 495 | |
| 496 | #if (defined(JUDYL) || (! defined(JU_64BIT))) |
| 497 | |
| 498 | // JPLEAF1: |
| 499 | |
| 500 | case cJU_JPLEAF1: |
| 501 | { |
| 502 | uint8_t * PLeaf1 = (uint8_t *) P_JLL(Pjp->jp_Addr); |
| 503 | |
| 504 | Pop1 = JU_JPBRANCH_POP0(Pjp, 1) + 1; assert(Pop1); |
| 505 | JUDYLCODE(Pjv1 = JL_LEAF1VALUEAREA(PLeaf1, Pop1);) |
| 506 | |
| 507 | // Copy all Index bytes including splicing in missing MSByte needed in Leaf2 |
| 508 | // (plus, for JudyL, value areas): |
| 509 | |
| 510 | for (Offset = 0; Offset < Pop1; ++Offset) |
| 511 | { |
| 512 | PLeaf2[Offset] = MSByte | PLeaf1[Offset]; |
| 513 | JUDYLCODE(Pjv2[Offset] = Pjv1[Offset];) |
| 514 | } |
| 515 | j__udyFreeJLL1((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 516 | return(Pop1); |
| 517 | } |
| 518 | #endif // (JUDYL || (! JU_64BIT)) |
| 519 | |
| 520 | |
| 521 | // JPIMMED_1_01: |
| 522 | // |
| 523 | // Note: jp_DcdPopO has 3 [7] bytes of Index (all but most significant byte), |
| 524 | // so the assignment to PLeaf2[] truncates and MSByte is not needed. |
| 525 | |
| 526 | case cJU_JPIMMED_1_01: |
| 527 | { |
| 528 | PLeaf2[0] = JU_JPDCDPOP0(Pjp); // see above. |
| 529 | JUDYLCODE(Pjv2[0] = Pjp->jp_Addr;) |
| 530 | return(1); |
| 531 | } |
| 532 | |
| 533 | |
| 534 | // JPIMMED_1_0[2+]: |
| 535 | |
| 536 | case cJU_JPIMMED_1_02: |
| 537 | case cJU_JPIMMED_1_03: |
| 538 | #if (defined(JUDY1) || defined(JU_64BIT)) |
| 539 | case cJU_JPIMMED_1_04: |
| 540 | case cJU_JPIMMED_1_05: |
| 541 | case cJU_JPIMMED_1_06: |
| 542 | case cJU_JPIMMED_1_07: |
| 543 | #endif |
| 544 | #if (defined(JUDY1) && defined(JU_64BIT)) |
| 545 | case cJ1_JPIMMED_1_08: |
| 546 | case cJ1_JPIMMED_1_09: |
| 547 | case cJ1_JPIMMED_1_10: |
| 548 | case cJ1_JPIMMED_1_11: |
| 549 | case cJ1_JPIMMED_1_12: |
| 550 | case cJ1_JPIMMED_1_13: |
| 551 | case cJ1_JPIMMED_1_14: |
| 552 | case cJ1_JPIMMED_1_15: |
| 553 | #endif |
| 554 | { |
| 555 | Pop1 = JU_JPTYPE(Pjp) - cJU_JPIMMED_1_02 + 2; assert(Pop1); |
| 556 | JUDYLCODE(Pjv1Raw = (Pjv_t) (Pjp->jp_Addr);) |
| 557 | JUDYLCODE(Pjv1 = P_JV(Pjv1Raw);) |
| 558 | |
| 559 | for (Offset = 0; Offset < Pop1; ++Offset) |
| 560 | { |
| 561 | #ifdef JUDY1 |
| 562 | PLeaf2[Offset] = MSByte | Pjp->jp_1Index[Offset]; |
| 563 | #else |
| 564 | PLeaf2[Offset] = MSByte | Pjp->jp_LIndex[Offset]; |
| 565 | Pjv2 [Offset] = Pjv1[Offset]; |
| 566 | #endif |
| 567 | } |
| 568 | JUDYLCODE(j__udyLFreeJV(Pjv1Raw, Pop1, Pjpm);) |
| 569 | return(Pop1); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | // UNEXPECTED CASES, including JPNULL1, should be handled by caller: |
| 574 | |
| 575 | default: assert(FALSE); break; |
| 576 | |
| 577 | } // switch |
| 578 | |
| 579 | return(0); |
| 580 | |
| 581 | } // j__udyLeaf1ToLeaf2() |
| 582 | |
| 583 | |
| 584 | // ***************************************************************************** |
| 585 | // __ J U D Y L E A F 2 T O L E A F 3 |
| 586 | // |
| 587 | // Copy 2-byte Indexes from a Leaf2 to 3-byte Indexes in a Leaf3. |
| 588 | // Pjp MUST be one of: cJU_JPLEAF2 or cJU_JPIMMED_2_*. |
| 589 | // Return number of Indexes copied. |
| 590 | // |
| 591 | // Note: By the time this function is called to compress a level-3 branch to a |
| 592 | // Leaf3, the branch has no narrow pointers under it, meaning only level-2 |
| 593 | // objects are below it and must be handled here. |
| 594 | |
| 595 | FUNCTION Word_t j__udyLeaf2ToLeaf3( |
| 596 | uint8_t * PLeaf3, // destination "uint24_t *" Index part of leaf. |
| 597 | #ifdef JUDYL |
| 598 | Pjv_t Pjv3, // destination value part of leaf. |
| 599 | #endif |
| 600 | Pjp_t Pjp, // 2-byte-index object from which to copy. |
| 601 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 602 | Pvoid_t Pjpm) // for global accounting. |
| 603 | { |
| 604 | Word_t Pop1; // Indexes in leaf. |
| 605 | #if (defined(JUDYL) && defined(JU_64BIT)) |
| 606 | Pjv_t Pjv2Raw; // source object value area. |
| 607 | #endif |
| 608 | JUDYLCODE(Pjv_t Pjv2;) |
| 609 | |
| 610 | switch (JU_JPTYPE(Pjp)) |
| 611 | { |
| 612 | |
| 613 | |
| 614 | // JPLEAF2: |
| 615 | |
| 616 | case cJU_JPLEAF2: |
| 617 | { |
| 618 | uint16_t * PLeaf2 = (uint16_t *) P_JLL(Pjp->jp_Addr); |
| 619 | |
| 620 | Pop1 = JU_JPLEAF_POP0(Pjp) + 1; assert(Pop1); |
| 621 | j__udyCopy2to3(PLeaf3, PLeaf2, Pop1, MSByte); |
| 622 | #ifdef JUDYL |
| 623 | Pjv2 = JL_LEAF2VALUEAREA(PLeaf2, Pop1); |
| 624 | JU_COPYMEM(Pjv3, Pjv2, Pop1); |
| 625 | #endif |
| 626 | j__udyFreeJLL2((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 627 | return(Pop1); |
| 628 | } |
| 629 | |
| 630 | |
| 631 | // JPIMMED_2_01: |
| 632 | // |
| 633 | // Note: jp_DcdPopO has 3 [7] bytes of Index (all but most significant byte), |
| 634 | // so the "assignment" to PLeaf3[] is exact [truncates] and MSByte is not |
| 635 | // needed. |
| 636 | |
| 637 | case cJU_JPIMMED_2_01: |
| 638 | { |
| 639 | JU_COPY3_LONG_TO_PINDEX(PLeaf3, JU_JPDCDPOP0(Pjp)); // see above. |
| 640 | JUDYLCODE(Pjv3[0] = Pjp->jp_Addr;) |
| 641 | return(1); |
| 642 | } |
| 643 | |
| 644 | |
| 645 | // JPIMMED_2_0[2+]: |
| 646 | |
| 647 | #if (defined(JUDY1) || defined(JU_64BIT)) |
| 648 | case cJU_JPIMMED_2_02: |
| 649 | case cJU_JPIMMED_2_03: |
| 650 | #endif |
| 651 | #if (defined(JUDY1) && defined(JU_64BIT)) |
| 652 | case cJ1_JPIMMED_2_04: |
| 653 | case cJ1_JPIMMED_2_05: |
| 654 | case cJ1_JPIMMED_2_06: |
| 655 | case cJ1_JPIMMED_2_07: |
| 656 | #endif |
| 657 | #if (defined(JUDY1) || defined(JU_64BIT)) |
| 658 | { |
| 659 | JUDY1CODE(uint16_t * PLeaf2 = (uint16_t *) (Pjp->jp_1Index);) |
| 660 | JUDYLCODE(uint16_t * PLeaf2 = (uint16_t *) (Pjp->jp_LIndex);) |
| 661 | |
| 662 | Pop1 = JU_JPTYPE(Pjp) - cJU_JPIMMED_2_02 + 2; assert(Pop1); |
| 663 | j__udyCopy2to3(PLeaf3, PLeaf2, Pop1, MSByte); |
| 664 | #ifdef JUDYL |
| 665 | Pjv2Raw = (Pjv_t) (Pjp->jp_Addr); |
| 666 | Pjv2 = P_JV(Pjv2Raw); |
| 667 | JU_COPYMEM(Pjv3, Pjv2, Pop1); |
| 668 | j__udyLFreeJV(Pjv2Raw, Pop1, Pjpm); |
| 669 | #endif |
| 670 | return(Pop1); |
| 671 | } |
| 672 | #endif // (JUDY1 || JU_64BIT) |
| 673 | |
| 674 | |
| 675 | // UNEXPECTED CASES, including JPNULL2, should be handled by caller: |
| 676 | |
| 677 | default: assert(FALSE); break; |
| 678 | |
| 679 | } // switch |
| 680 | |
| 681 | return(0); |
| 682 | |
| 683 | } // j__udyLeaf2ToLeaf3() |
| 684 | |
| 685 | |
| 686 | #ifdef JU_64BIT |
| 687 | |
| 688 | // **************************************************************************** |
| 689 | // __ J U D Y L E A F 3 T O L E A F 4 |
| 690 | // |
| 691 | // Copy 3-byte Indexes from a Leaf3 to 4-byte Indexes in a Leaf4. |
| 692 | // Pjp MUST be one of: cJU_JPLEAF3 or cJU_JPIMMED_3_*. |
| 693 | // Return number of Indexes copied. |
| 694 | // |
| 695 | // Note: By the time this function is called to compress a level-4 branch to a |
| 696 | // Leaf4, the branch has no narrow pointers under it, meaning only level-3 |
| 697 | // objects are below it and must be handled here. |
| 698 | |
| 699 | FUNCTION Word_t j__udyLeaf3ToLeaf4( |
| 700 | uint32_t * PLeaf4, // destination uint32_t * Index part of leaf. |
| 701 | #ifdef JUDYL |
| 702 | Pjv_t Pjv4, // destination value part of leaf. |
| 703 | #endif |
| 704 | Pjp_t Pjp, // 3-byte-index object from which to copy. |
| 705 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 706 | Pvoid_t Pjpm) // for global accounting. |
| 707 | { |
| 708 | Word_t Pop1; // Indexes in leaf. |
| 709 | JUDYLCODE(Pjv_t Pjv3Raw;) // source object value area. |
| 710 | JUDYLCODE(Pjv_t Pjv3;) |
| 711 | |
| 712 | switch (JU_JPTYPE(Pjp)) |
| 713 | { |
| 714 | |
| 715 | |
| 716 | // JPLEAF3: |
| 717 | |
| 718 | case cJU_JPLEAF3: |
| 719 | { |
| 720 | uint8_t * PLeaf3 = (uint8_t *) P_JLL(Pjp->jp_Addr); |
| 721 | |
| 722 | Pop1 = JU_JPLEAF_POP0(Pjp) + 1; assert(Pop1); |
| 723 | j__udyCopy3to4(PLeaf4, (uint8_t *) PLeaf3, Pop1, MSByte); |
| 724 | #ifdef JUDYL |
| 725 | Pjv3 = JL_LEAF3VALUEAREA(PLeaf3, Pop1); |
| 726 | JU_COPYMEM(Pjv4, Pjv3, Pop1); |
| 727 | #endif |
| 728 | j__udyFreeJLL3((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 729 | return(Pop1); |
| 730 | } |
| 731 | |
| 732 | |
| 733 | // JPIMMED_3_01: |
| 734 | // |
| 735 | // Note: jp_DcdPopO has 7 bytes of Index (all but most significant byte), so |
| 736 | // the assignment to PLeaf4[] truncates and MSByte is not needed. |
| 737 | |
| 738 | case cJU_JPIMMED_3_01: |
| 739 | { |
| 740 | PLeaf4[0] = JU_JPDCDPOP0(Pjp); // see above. |
| 741 | JUDYLCODE(Pjv4[0] = Pjp->jp_Addr;) |
| 742 | return(1); |
| 743 | } |
| 744 | |
| 745 | |
| 746 | // JPIMMED_3_0[2+]: |
| 747 | |
| 748 | case cJU_JPIMMED_3_02: |
| 749 | #ifdef JUDY1 |
| 750 | case cJ1_JPIMMED_3_03: |
| 751 | case cJ1_JPIMMED_3_04: |
| 752 | case cJ1_JPIMMED_3_05: |
| 753 | #endif |
| 754 | { |
| 755 | JUDY1CODE(uint8_t * PLeaf3 = (uint8_t *) (Pjp->jp_1Index);) |
| 756 | JUDYLCODE(uint8_t * PLeaf3 = (uint8_t *) (Pjp->jp_LIndex);) |
| 757 | |
| 758 | JUDY1CODE(Pop1 = JU_JPTYPE(Pjp) - cJU_JPIMMED_3_02 + 2;) |
| 759 | JUDYLCODE(Pop1 = 2;) |
| 760 | |
| 761 | j__udyCopy3to4(PLeaf4, PLeaf3, Pop1, MSByte); |
| 762 | #ifdef JUDYL |
| 763 | Pjv3Raw = (Pjv_t) (Pjp->jp_Addr); |
| 764 | Pjv3 = P_JV(Pjv3Raw); |
| 765 | JU_COPYMEM(Pjv4, Pjv3, Pop1); |
| 766 | j__udyLFreeJV(Pjv3Raw, Pop1, Pjpm); |
| 767 | #endif |
| 768 | return(Pop1); |
| 769 | } |
| 770 | |
| 771 | |
| 772 | // UNEXPECTED CASES, including JPNULL3, should be handled by caller: |
| 773 | |
| 774 | default: assert(FALSE); break; |
| 775 | |
| 776 | } // switch |
| 777 | |
| 778 | return(0); |
| 779 | |
| 780 | } // j__udyLeaf3ToLeaf4() |
| 781 | |
| 782 | |
| 783 | // Note: In all following j__udyLeaf*ToLeaf*() functions, JPIMMED_*_0[2+] |
| 784 | // cases exist for Judy1 (&& 64-bit) only. JudyL has no equivalent Immeds. |
| 785 | |
| 786 | |
| 787 | // ***************************************************************************** |
| 788 | // __ J U D Y L E A F 4 T O L E A F 5 |
| 789 | // |
| 790 | // Copy 4-byte Indexes from a Leaf4 to 5-byte Indexes in a Leaf5. |
| 791 | // Pjp MUST be one of: cJU_JPLEAF4 or cJU_JPIMMED_4_*. |
| 792 | // Return number of Indexes copied. |
| 793 | // |
| 794 | // Note: By the time this function is called to compress a level-5 branch to a |
| 795 | // Leaf5, the branch has no narrow pointers under it, meaning only level-4 |
| 796 | // objects are below it and must be handled here. |
| 797 | |
| 798 | FUNCTION Word_t j__udyLeaf4ToLeaf5( |
| 799 | uint8_t * PLeaf5, // destination "uint40_t *" Index part of leaf. |
| 800 | #ifdef JUDYL |
| 801 | Pjv_t Pjv5, // destination value part of leaf. |
| 802 | #endif |
| 803 | Pjp_t Pjp, // 4-byte-index object from which to copy. |
| 804 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 805 | Pvoid_t Pjpm) // for global accounting. |
| 806 | { |
| 807 | Word_t Pop1; // Indexes in leaf. |
| 808 | JUDYLCODE(Pjv_t Pjv4;) // source object value area. |
| 809 | |
| 810 | switch (JU_JPTYPE(Pjp)) |
| 811 | { |
| 812 | |
| 813 | |
| 814 | // JPLEAF4: |
| 815 | |
| 816 | case cJU_JPLEAF4: |
| 817 | { |
| 818 | uint32_t * PLeaf4 = (uint32_t *) P_JLL(Pjp->jp_Addr); |
| 819 | |
| 820 | Pop1 = JU_JPLEAF_POP0(Pjp) + 1; assert(Pop1); |
| 821 | j__udyCopy4to5(PLeaf5, PLeaf4, Pop1, MSByte); |
| 822 | #ifdef JUDYL |
| 823 | Pjv4 = JL_LEAF4VALUEAREA(PLeaf4, Pop1); |
| 824 | JU_COPYMEM(Pjv5, Pjv4, Pop1); |
| 825 | #endif |
| 826 | j__udyFreeJLL4((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 827 | return(Pop1); |
| 828 | } |
| 829 | |
| 830 | |
| 831 | // JPIMMED_4_01: |
| 832 | // |
| 833 | // Note: jp_DcdPopO has 7 bytes of Index (all but most significant byte), so |
| 834 | // the assignment to PLeaf5[] truncates and MSByte is not needed. |
| 835 | |
| 836 | case cJU_JPIMMED_4_01: |
| 837 | { |
| 838 | JU_COPY5_LONG_TO_PINDEX(PLeaf5, JU_JPDCDPOP0(Pjp)); // see above. |
| 839 | JUDYLCODE(Pjv5[0] = Pjp->jp_Addr;) |
| 840 | return(1); |
| 841 | } |
| 842 | |
| 843 | |
| 844 | #ifdef JUDY1 |
| 845 | |
| 846 | // JPIMMED_4_0[4+]: |
| 847 | |
| 848 | case cJ1_JPIMMED_4_02: |
| 849 | case cJ1_JPIMMED_4_03: |
| 850 | { |
| 851 | uint32_t * PLeaf4 = (uint32_t *) (Pjp->jp_1Index); |
| 852 | |
| 853 | Pop1 = JU_JPTYPE(Pjp) - cJ1_JPIMMED_4_02 + 2; |
| 854 | j__udyCopy4to5(PLeaf5, PLeaf4, Pop1, MSByte); |
| 855 | return(Pop1); |
| 856 | } |
| 857 | #endif // JUDY1 |
| 858 | |
| 859 | |
| 860 | // UNEXPECTED CASES, including JPNULL4, should be handled by caller: |
| 861 | |
| 862 | default: assert(FALSE); break; |
| 863 | |
| 864 | } // switch |
| 865 | |
| 866 | return(0); |
| 867 | |
| 868 | } // j__udyLeaf4ToLeaf5() |
| 869 | |
| 870 | |
| 871 | // **************************************************************************** |
| 872 | // __ J U D Y L E A F 5 T O L E A F 6 |
| 873 | // |
| 874 | // Copy 5-byte Indexes from a Leaf5 to 6-byte Indexes in a Leaf6. |
| 875 | // Pjp MUST be one of: cJU_JPLEAF5 or cJU_JPIMMED_5_*. |
| 876 | // Return number of Indexes copied. |
| 877 | // |
| 878 | // Note: By the time this function is called to compress a level-6 branch to a |
| 879 | // Leaf6, the branch has no narrow pointers under it, meaning only level-5 |
| 880 | // objects are below it and must be handled here. |
| 881 | |
| 882 | FUNCTION Word_t j__udyLeaf5ToLeaf6( |
| 883 | uint8_t * PLeaf6, // destination uint8_t * Index part of leaf. |
| 884 | #ifdef JUDYL |
| 885 | Pjv_t Pjv6, // destination value part of leaf. |
| 886 | #endif |
| 887 | Pjp_t Pjp, // 5-byte-index object from which to copy. |
| 888 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 889 | Pvoid_t Pjpm) // for global accounting. |
| 890 | { |
| 891 | Word_t Pop1; // Indexes in leaf. |
| 892 | JUDYLCODE(Pjv_t Pjv5;) // source object value area. |
| 893 | |
| 894 | switch (JU_JPTYPE(Pjp)) |
| 895 | { |
| 896 | |
| 897 | |
| 898 | // JPLEAF5: |
| 899 | |
| 900 | case cJU_JPLEAF5: |
| 901 | { |
| 902 | uint8_t * PLeaf5 = (uint8_t *) P_JLL(Pjp->jp_Addr); |
| 903 | |
| 904 | Pop1 = JU_JPLEAF_POP0(Pjp) + 1; assert(Pop1); |
| 905 | j__udyCopy5to6(PLeaf6, PLeaf5, Pop1, MSByte); |
| 906 | #ifdef JUDYL |
| 907 | Pjv5 = JL_LEAF5VALUEAREA(PLeaf5, Pop1); |
| 908 | JU_COPYMEM(Pjv6, Pjv5, Pop1); |
| 909 | #endif |
| 910 | j__udyFreeJLL5((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 911 | return(Pop1); |
| 912 | } |
| 913 | |
| 914 | |
| 915 | // JPIMMED_5_01: |
| 916 | // |
| 917 | // Note: jp_DcdPopO has 7 bytes of Index (all but most significant byte), so |
| 918 | // the assignment to PLeaf6[] truncates and MSByte is not needed. |
| 919 | |
| 920 | case cJU_JPIMMED_5_01: |
| 921 | { |
| 922 | JU_COPY6_LONG_TO_PINDEX(PLeaf6, JU_JPDCDPOP0(Pjp)); // see above. |
| 923 | JUDYLCODE(Pjv6[0] = Pjp->jp_Addr;) |
| 924 | return(1); |
| 925 | } |
| 926 | |
| 927 | |
| 928 | #ifdef JUDY1 |
| 929 | |
| 930 | // JPIMMED_5_0[2+]: |
| 931 | |
| 932 | case cJ1_JPIMMED_5_02: |
| 933 | case cJ1_JPIMMED_5_03: |
| 934 | { |
| 935 | uint8_t * PLeaf5 = (uint8_t *) (Pjp->jp_1Index); |
| 936 | |
| 937 | Pop1 = JU_JPTYPE(Pjp) - cJ1_JPIMMED_5_02 + 2; |
| 938 | j__udyCopy5to6(PLeaf6, PLeaf5, Pop1, MSByte); |
| 939 | return(Pop1); |
| 940 | } |
| 941 | #endif // JUDY1 |
| 942 | |
| 943 | |
| 944 | // UNEXPECTED CASES, including JPNULL5, should be handled by caller: |
| 945 | |
| 946 | default: assert(FALSE); break; |
| 947 | |
| 948 | } // switch |
| 949 | |
| 950 | return(0); |
| 951 | |
| 952 | } // j__udyLeaf5ToLeaf6() |
| 953 | |
| 954 | |
| 955 | // ***************************************************************************** |
| 956 | // __ J U D Y L E A F 6 T O L E A F 7 |
| 957 | // |
| 958 | // Copy 6-byte Indexes from a Leaf2 to 7-byte Indexes in a Leaf7. |
| 959 | // Pjp MUST be one of: cJU_JPLEAF6 or cJU_JPIMMED_6_*. |
| 960 | // Return number of Indexes copied. |
| 961 | // |
| 962 | // Note: By the time this function is called to compress a level-7 branch to a |
| 963 | // Leaf7, the branch has no narrow pointers under it, meaning only level-6 |
| 964 | // objects are below it and must be handled here. |
| 965 | |
| 966 | FUNCTION Word_t j__udyLeaf6ToLeaf7( |
| 967 | uint8_t * PLeaf7, // destination "uint24_t *" Index part of leaf. |
| 968 | #ifdef JUDYL |
| 969 | Pjv_t Pjv7, // destination value part of leaf. |
| 970 | #endif |
| 971 | Pjp_t Pjp, // 6-byte-index object from which to copy. |
| 972 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 973 | Pvoid_t Pjpm) // for global accounting. |
| 974 | { |
| 975 | Word_t Pop1; // Indexes in leaf. |
| 976 | JUDYLCODE(Pjv_t Pjv6;) // source object value area. |
| 977 | |
| 978 | switch (JU_JPTYPE(Pjp)) |
| 979 | { |
| 980 | |
| 981 | |
| 982 | // JPLEAF6: |
| 983 | |
| 984 | case cJU_JPLEAF6: |
| 985 | { |
| 986 | uint8_t * PLeaf6 = (uint8_t *) P_JLL(Pjp->jp_Addr); |
| 987 | |
| 988 | Pop1 = JU_JPLEAF_POP0(Pjp) + 1; |
| 989 | j__udyCopy6to7(PLeaf7, PLeaf6, Pop1, MSByte); |
| 990 | #ifdef JUDYL |
| 991 | Pjv6 = JL_LEAF6VALUEAREA(PLeaf6, Pop1); |
| 992 | JU_COPYMEM(Pjv7, Pjv6, Pop1); |
| 993 | #endif |
| 994 | j__udyFreeJLL6((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 995 | return(Pop1); |
| 996 | } |
| 997 | |
| 998 | |
| 999 | // JPIMMED_6_01: |
| 1000 | // |
| 1001 | // Note: jp_DcdPopO has 7 bytes of Index (all but most significant byte), so |
| 1002 | // the "assignment" to PLeaf7[] is exact and MSByte is not needed. |
| 1003 | |
| 1004 | case cJU_JPIMMED_6_01: |
| 1005 | { |
| 1006 | JU_COPY7_LONG_TO_PINDEX(PLeaf7, JU_JPDCDPOP0(Pjp)); // see above. |
| 1007 | JUDYLCODE(Pjv7[0] = Pjp->jp_Addr;) |
| 1008 | return(1); |
| 1009 | } |
| 1010 | |
| 1011 | |
| 1012 | #ifdef JUDY1 |
| 1013 | |
| 1014 | // JPIMMED_6_02: |
| 1015 | |
| 1016 | case cJ1_JPIMMED_6_02: |
| 1017 | { |
| 1018 | uint8_t * PLeaf6 = (uint8_t *) (Pjp->jp_1Index); |
| 1019 | |
| 1020 | j__udyCopy6to7(PLeaf7, PLeaf6, /* Pop1 = */ 2, MSByte); |
| 1021 | return(2); |
| 1022 | } |
| 1023 | #endif // JUDY1 |
| 1024 | |
| 1025 | |
| 1026 | // UNEXPECTED CASES, including JPNULL6, should be handled by caller: |
| 1027 | |
| 1028 | default: assert(FALSE); break; |
| 1029 | |
| 1030 | } // switch |
| 1031 | |
| 1032 | return(0); |
| 1033 | |
| 1034 | } // j__udyLeaf6ToLeaf7() |
| 1035 | |
| 1036 | #endif // JU_64BIT |
| 1037 | |
| 1038 | |
| 1039 | #ifndef JU_64BIT // 32-bit version first |
| 1040 | |
| 1041 | // **************************************************************************** |
| 1042 | // __ J U D Y L E A F 3 T O L E A F W |
| 1043 | // |
| 1044 | // Copy 3-byte Indexes from a Leaf3 to 4-byte Indexes in a LeafW. Pjp MUST be |
| 1045 | // one of: cJU_JPLEAF3 or cJU_JPIMMED_3_*. Return number of Indexes copied. |
| 1046 | // |
| 1047 | // Note: By the time this function is called to compress a level-L branch to a |
| 1048 | // LeafW, the branch has no narrow pointers under it, meaning only level-3 |
| 1049 | // objects are below it and must be handled here. |
| 1050 | |
| 1051 | FUNCTION Word_t j__udyLeaf3ToLeafW( |
| 1052 | Pjlw_t Pjlw, // destination Index part of leaf. |
| 1053 | #ifdef JUDYL |
| 1054 | Pjv_t PjvW, // destination value part of leaf. |
| 1055 | #endif |
| 1056 | Pjp_t Pjp, // 3-byte-index object from which to copy. |
| 1057 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 1058 | Pvoid_t Pjpm) // for global accounting. |
| 1059 | { |
| 1060 | Word_t Pop1; // Indexes in leaf. |
| 1061 | JUDYLCODE(Pjv_t Pjv3;) // source object value area. |
| 1062 | |
| 1063 | switch (JU_JPTYPE(Pjp)) |
| 1064 | { |
| 1065 | |
| 1066 | |
| 1067 | // JPLEAF3: |
| 1068 | |
| 1069 | case cJU_JPLEAF3: |
| 1070 | { |
| 1071 | uint8_t * PLeaf3 = (uint8_t *) P_JLL(Pjp->jp_Addr); |
| 1072 | |
| 1073 | Pop1 = JU_JPLEAF_POP0(Pjp) + 1; |
| 1074 | j__udyCopy3toW((PWord_t) Pjlw, PLeaf3, Pop1, MSByte); |
| 1075 | #ifdef JUDYL |
| 1076 | Pjv3 = JL_LEAF3VALUEAREA(PLeaf3, Pop1); |
| 1077 | JU_COPYMEM(PjvW, Pjv3, Pop1); |
| 1078 | #endif |
| 1079 | j__udyFreeJLL3((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 1080 | return(Pop1); |
| 1081 | } |
| 1082 | |
| 1083 | |
| 1084 | // JPIMMED_3_01: |
| 1085 | // |
| 1086 | // Note: jp_DcdPopO has 3 bytes of Index (all but most significant byte), and |
| 1087 | // MSByte must be ord in. |
| 1088 | |
| 1089 | case cJU_JPIMMED_3_01: |
| 1090 | { |
| 1091 | Pjlw[0] = MSByte | JU_JPDCDPOP0(Pjp); // see above. |
| 1092 | JUDYLCODE(PjvW[0] = Pjp->jp_Addr;) |
| 1093 | return(1); |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | #ifdef JUDY1 |
| 1098 | |
| 1099 | // JPIMMED_3_02: |
| 1100 | |
| 1101 | case cJU_JPIMMED_3_02: |
| 1102 | { |
| 1103 | uint8_t * PLeaf3 = (uint8_t *) (Pjp->jp_1Index); |
| 1104 | |
| 1105 | j__udyCopy3toW((PWord_t) Pjlw, PLeaf3, /* Pop1 = */ 2, MSByte); |
| 1106 | return(2); |
| 1107 | } |
| 1108 | #endif // JUDY1 |
| 1109 | |
| 1110 | |
| 1111 | // UNEXPECTED CASES, including JPNULL3, should be handled by caller: |
| 1112 | |
| 1113 | default: assert(FALSE); break; |
| 1114 | |
| 1115 | } // switch |
| 1116 | |
| 1117 | return(0); |
| 1118 | |
| 1119 | } // j__udyLeaf3ToLeafW() |
| 1120 | |
| 1121 | |
| 1122 | #else // JU_64BIT |
| 1123 | |
| 1124 | |
| 1125 | // **************************************************************************** |
| 1126 | // __ J U D Y L E A F 7 T O L E A F W |
| 1127 | // |
| 1128 | // Copy 7-byte Indexes from a Leaf7 to 8-byte Indexes in a LeafW. |
| 1129 | // Pjp MUST be one of: cJU_JPLEAF7 or cJU_JPIMMED_7_*. |
| 1130 | // Return number of Indexes copied. |
| 1131 | // |
| 1132 | // Note: By the time this function is called to compress a level-L branch to a |
| 1133 | // LeafW, the branch has no narrow pointers under it, meaning only level-7 |
| 1134 | // objects are below it and must be handled here. |
| 1135 | |
| 1136 | FUNCTION Word_t j__udyLeaf7ToLeafW( |
| 1137 | Pjlw_t Pjlw, // destination Index part of leaf. |
| 1138 | #ifdef JUDYL |
| 1139 | Pjv_t PjvW, // destination value part of leaf. |
| 1140 | #endif |
| 1141 | Pjp_t Pjp, // 7-byte-index object from which to copy. |
| 1142 | Word_t MSByte, // most-significant byte, prefix to each Index. |
| 1143 | Pvoid_t Pjpm) // for global accounting. |
| 1144 | { |
| 1145 | Word_t Pop1; // Indexes in leaf. |
| 1146 | JUDYLCODE(Pjv_t Pjv7;) // source object value area. |
| 1147 | |
| 1148 | switch (JU_JPTYPE(Pjp)) |
| 1149 | { |
| 1150 | |
| 1151 | |
| 1152 | // JPLEAF7: |
| 1153 | |
| 1154 | case cJU_JPLEAF7: |
| 1155 | { |
| 1156 | uint8_t * PLeaf7 = (uint8_t *) P_JLL(Pjp->jp_Addr); |
| 1157 | |
| 1158 | Pop1 = JU_JPLEAF_POP0(Pjp) + 1; |
| 1159 | j__udyCopy7toW((PWord_t) Pjlw, PLeaf7, Pop1, MSByte); |
| 1160 | #ifdef JUDYL |
| 1161 | Pjv7 = JL_LEAF7VALUEAREA(PLeaf7, Pop1); |
| 1162 | JU_COPYMEM(PjvW, Pjv7, Pop1); |
| 1163 | #endif |
| 1164 | j__udyFreeJLL7((Pjll_t) (Pjp->jp_Addr), Pop1, Pjpm); |
| 1165 | return(Pop1); |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | // JPIMMED_7_01: |
| 1170 | // |
| 1171 | // Note: jp_DcdPopO has 7 bytes of Index (all but most significant byte), and |
| 1172 | // MSByte must be ord in. |
| 1173 | |
| 1174 | case cJU_JPIMMED_7_01: |
| 1175 | { |
| 1176 | Pjlw[0] = MSByte | JU_JPDCDPOP0(Pjp); // see above. |
| 1177 | JUDYLCODE(PjvW[0] = Pjp->jp_Addr;) |
| 1178 | return(1); |
| 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | #ifdef JUDY1 |
| 1183 | |
| 1184 | // JPIMMED_7_02: |
| 1185 | |
| 1186 | case cJ1_JPIMMED_7_02: |
| 1187 | { |
| 1188 | uint8_t * PLeaf7 = (uint8_t *) (Pjp->jp_1Index); |
| 1189 | |
| 1190 | j__udyCopy7toW((PWord_t) Pjlw, PLeaf7, /* Pop1 = */ 2, MSByte); |
| 1191 | return(2); |
| 1192 | } |
| 1193 | #endif |
| 1194 | |
| 1195 | |
| 1196 | // UNEXPECTED CASES, including JPNULL7, should be handled by caller: |
| 1197 | |
| 1198 | default: assert(FALSE); break; |
| 1199 | |
| 1200 | } // switch |
| 1201 | |
| 1202 | return(0); |
| 1203 | |
| 1204 | } // j__udyLeaf7ToLeafW() |
| 1205 | |
| 1206 | #endif // JU_64BIT |