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