Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/src/JudyCommon/JudyDecascade.c view on Meta::CPAN
Pjp_t Pjpjbl; // current JP in BranchL.
Word_t SubExp; // in BranchB.
assert(JU_JPTYPE(Pjp) >= cJU_JPBRANCH_B2);
assert(JU_JPTYPE(Pjp) <= cJU_JPBRANCH_B);
PjbbRaw = (Pjbb_t) (Pjp->jp_Addr);
Pjbb = P_JBB(PjbbRaw);
// Copy 1-byte subexpanse digits from BranchB to temporary buffer for BranchL,
// for each bit set in the BranchB:
//
// TBD: The following supports variable-sized linear branches, but they are no
// longer variable; this could be simplified to save the copying.
//
// TBD: Since cJU_BRANCHLMAXJP == 7 now, and cJU_BRANCHUNUMJPS == 256, the
// following might be inefficient; is there a faster way to do it? At least
// skip wholly empty subexpanses?
for (NumJPs = Digit = 0; Digit < cJU_BRANCHUNUMJPS; ++Digit)
{
if (JU_BITMAPTESTB(Pjbb, Digit))
{
Expanse[NumJPs++] = Digit;
assert(NumJPs <= cJU_BRANCHLMAXJPS); // required of caller.
}
}
// Allocate and populate the BranchL:
if ((PjblRaw = j__udyAllocJBL(Pjpm)) == (Pjbl_t) NULL) return(-1);
Pjbl = P_JBL(PjblRaw);
JU_COPYMEM(Pjbl->jbl_Expanse, Expanse, NumJPs);
Pjbl->jbl_NumJPs = NumJPs;
DBGCODE(JudyCheckSorted((Pjll_t) (Pjbl->jbl_Expanse), NumJPs, 1);)
// Copy JPs from each BranchB subexpanse subarray:
Pjpjbl = P_JP(Pjbl->jbl_jp); // start at first JP in array.
for (SubExp = 0; SubExp < cJU_NUMSUBEXPB; ++SubExp)
{
Pjp_t PjpRaw = JU_JBB_PJP(Pjbb, SubExp); // current Pjp.
Pjp_t Pjp;
if (PjpRaw == (Pjp_t) NULL) continue; // skip empty subexpanse.
Pjp = P_JP(PjpRaw);
NumJPs = j__udyCountBitsB(JU_JBB_BITMAP(Pjbb, SubExp));
assert(NumJPs);
JU_COPYMEM(Pjpjbl, Pjp, NumJPs); // one subarray at a time.
Pjpjbl += NumJPs;
j__udyFreeJBBJP(PjpRaw, NumJPs, Pjpm); // subarray.
}
j__udyFreeJBB(PjbbRaw, Pjpm); // BranchB itself.
// Finish up: Calculate new JP type (same index size = level in new class),
// and tie new BranchB into parent JP:
Pjp->jp_Type += cJU_JPBRANCH_L - cJU_JPBRANCH_B;
Pjp->jp_Addr = (Word_t) PjblRaw;
return(1);
} // j__udyBranchBToBranchL()
#ifdef notdef
// ****************************************************************************
// __ J U D Y B R A N C H U T O B R A N C H B
//
// When a BranchU shrinks to need little enough memory, call this function to
// convert it to a BranchB to save memory (at the cost of some speed). Return
// 1 for success, or -1 for failure (with details in Pjpm).
//
// TBD: Fill out if/when needed. Not currently used in JudyDel.c for reasons
// explained there.
FUNCTION int j__udyBranchUToBranchB(
Pjp_t Pjp, // points to BranchU to shrink.
Pvoid_t Pjpm) // for global accounting.
{
assert(FALSE);
return(1);
}
#endif // notdef
#if (defined(JUDYL) || (! defined(JU_64BIT)))
// ****************************************************************************
// __ J U D Y L E A F B 1 T O L E A F 1
//
// Shrink a bitmap leaf (cJU_LEAFB1) to linear leaf (cJU_JPLEAF1).
// Return 1 for success, or -1 for failure (with details in Pjpm).
//
// Note: This function is different than the other JudyLeaf*ToLeaf*()
// functions because it receives a Pjp, not just a leaf, and handles its own
// allocation and free, in order to allow the caller to continue with a LeafB1
// if allocation fails.
FUNCTION int j__udyLeafB1ToLeaf1(
Pjp_t Pjp, // points to LeafB1 to shrink.
Pvoid_t Pjpm) // for global accounting.
{
Pjlb_t PjlbRaw; // bitmap in old leaf.
Pjlb_t Pjlb;
Pjll_t PjllRaw; // new Leaf1.
uint8_t * Pleaf1; // Leaf1 pointer type.
Word_t Digit; // in LeafB1 bitmap.
#ifdef JUDYL
Pjv_t PjvNew; // value area in new Leaf1.
Word_t Pop1;
Word_t SubExp;
#endif
assert(JU_JPTYPE(Pjp) == cJU_JPLEAF_B1);
( run in 0.717 second using v1.01-cache-2.11-cpan-2398b32b56e )