Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/src/JudyCommon/JudyIns.c view on Meta::CPAN
// Convert jp_Type from linear branch to equivalent bitmap branch:
Pjp->jp_Type += cJU_JPBRANCH_B - cJU_JPBRANCH_L;
j__udyFreeJBL(PjblRaw, Pjpm); // free old BranchL.
// Having changed branch types, now do the insert in the new branch type:
goto ContinueInsWalk;
// OPPORTUNISTICALLY CONVERT FROM BRANCHL TO BRANCHU:
//
// Memory efficiency is no object because the branchs pop1 is large enough, so
// speed up array access. Come here with PjblRaw set. Note: This is goto
// code because the previous block used to fall through into it as well, but no
// longer.
ConvertBranchLtoU:
// Allocate memory for an uncompressed branch:
if ((PjbuRaw = j__udyAllocJBU(Pjpm)) == (Pjbu_t) NULL)
return(-1);
Pjbu = P_JBU(PjbuRaw);
// Set the proper NULL type for most of the uncompressed branchs JPs:
JU_JPSETADT(&newJP, 0, 0,
JU_JPTYPE(Pjp) - cJU_JPBRANCH_L2 + cJU_JPNULL1);
// Initialize: Pre-set uncompressed branch to mostly JPNULL*s:
for (numJPs = 0; numJPs < cJU_BRANCHUNUMJPS; ++numJPs)
Pjbu->jbu_jp[numJPs] = newJP;
// Copy JPs from linear branch to uncompressed branch:
{
#ifdef SUBEXPCOUNTS
Word_t popmask = cJU_POP0MASK(JU_JPTYPE(Pjp))
- cJU_JPBRANCH_L2 - 2;
for (numJPs = 0; numJPs < cJU_NUMSUBEXPU; ++numJPs)
Pjbu->jbu_subPop1[numJPs] = 0;
#endif
for (numJPs = 0; numJPs < Pjbl->jbl_NumJPs; ++numJPs)
{
Pjp_t Pjp1 = &(Pjbl->jbl_jp[numJPs]);
offset = Pjbl->jbl_Expanse[numJPs];
Pjbu->jbu_jp[offset] = *Pjp1;
#ifdef SUBEXPCOUNTS
Pjbu->jbu_subPop1[offset/cJU_NUMSUBEXPU] +=
JU_JPDCDPOP0(Pjp1) & popmask + 1;
#endif
}
}
j__udyFreeJBL(PjblRaw, Pjpm); // free old BranchL.
// Plug new values into parent JP:
Pjp->jp_Addr = (Word_t) PjbuRaw;
Pjp->jp_Type += cJU_JPBRANCH_U - cJU_JPBRANCH_L; // to BranchU.
// Save global population of last BranchU conversion:
Pjpm->jpm_LastUPop0 = Pjpm->jpm_Pop0;
goto ContinueInsWalk;
} // case cJU_JPBRANCH_L.
// ****************************************************************************
// JPBRANCH_B*:
//
// If the new Index is not an outlier to the branchs expanse, extract the
// digit and record the Immediate type to create for a new Immed JP, before
// going to common code.
//
// Note: JU_CHECK_IF_OUTLIER() is a no-op for BranchB3[7] on 32[64]-bit.
case cJU_JPBRANCH_B2:
JU_BRANCH_OUTLIER(digit, exppop1, 2, Pjp, Index, Pjpm);
goto JudyBranchB;
case cJU_JPBRANCH_B3:
JU_BRANCH_OUTLIER(digit, exppop1, 3, Pjp, Index, Pjpm);
goto JudyBranchB;
#ifdef JU_64BIT
case cJU_JPBRANCH_B4:
JU_BRANCH_OUTLIER(digit, exppop1, 4, Pjp, Index, Pjpm);
goto JudyBranchB;
case cJU_JPBRANCH_B5:
JU_BRANCH_OUTLIER(digit, exppop1, 5, Pjp, Index, Pjpm);
goto JudyBranchB;
case cJU_JPBRANCH_B6:
JU_BRANCH_OUTLIER(digit, exppop1, 6, Pjp, Index, Pjpm);
goto JudyBranchB;
case cJU_JPBRANCH_B7:
JU_BRANCH_OUTLIER(digit, exppop1, 7, Pjp, Index, Pjpm);
goto JudyBranchB;
#endif
case cJU_JPBRANCH_B:
{
Pjbb_t Pjbb; // pointer to bitmap branch.
Pjbb_t PjbbRaw; // pointer to bitmap branch.
Pjp_t Pjp2Raw; // 1 of N arrays of JPs.
Pjp_t Pjp2; // 1 of N arrays of JPs.
Word_t subexp; // 1 of N subexpanses in bitmap.
BITMAPB_t bitmap; // for one subexpanse.
BITMAPB_t bitmask; // bit set for Indexs digit.
Word_t numJPs; // number of JPs = populated expanses.
int offset; // in bitmap branch.
// Similar to common code above, but no outlier check is needed, and the Immed
src/judy-1.0.5/src/JudyCommon/JudyIns.c view on Meta::CPAN
case cJU_JPIMMED_1_02:
#if (defined(JUDY1) || defined(JU_64BIT))
case cJU_JPIMMED_1_03:
case cJU_JPIMMED_1_04:
case cJU_JPIMMED_1_05:
case cJU_JPIMMED_1_06:
#endif
#if (defined(JUDY1) && defined(JU_64BIT))
case cJU_JPIMMED_1_07:
case cJ1_JPIMMED_1_08:
case cJ1_JPIMMED_1_09:
case cJ1_JPIMMED_1_10:
case cJ1_JPIMMED_1_11:
case cJ1_JPIMMED_1_12:
case cJ1_JPIMMED_1_13:
case cJ1_JPIMMED_1_14:
#endif
JU_IMMSETINPLACE(1, uint8_t *, cJU_JPIMMED_1_02, j__udySearchLeaf1,
JU_INSERTINPLACE);
// cJU_JPIMMED_1_* cases that must cascade:
//
// (1_01 => 1_02 => 1_03 => [ 1_04 => ... => 1_07 => [ 1_08..15 => ]] LeafL)
#if (defined(JUDYL) && (! defined(JU_64BIT)))
case cJU_JPIMMED_1_03:
JU_IMMSETCASCADE(1, 3, uint8_t *, cJU_JPLEAF1, JL_LEAF1VALUEAREA,
j__udySearchLeaf1, JU_INSERTCOPY,
j__udyAllocJLL1);
#endif
#if (defined(JUDY1) && (! defined(JU_64BIT)))
case cJU_JPIMMED_1_07:
JU_IMMSETCASCADE(1, 7, uint8_t *, cJU_JPLEAF1, ignore,
j__udySearchLeaf1, JU_INSERTCOPY,
j__udyAllocJLL1);
#endif
#if (defined(JUDYL) && defined(JU_64BIT))
case cJU_JPIMMED_1_07:
JU_IMMSETCASCADE(1, 7, uint8_t *, cJU_JPLEAF1, JL_LEAF1VALUEAREA,
j__udySearchLeaf1, JU_INSERTCOPY,
j__udyAllocJLL1);
#endif
#if (defined(JUDY1) && defined(JU_64BIT))
// Special case, as described above, go directly from Immed to LeafB1:
case cJ1_JPIMMED_1_15:
{
Word_t DcdP0;
int offset;
Pjlb_t PjlbRaw;
Pjlb_t Pjlb;
offset = j__udySearchLeaf1((Pjll_t) Pjp->jp_1Index, 15, Index);
JU_CHECK_IF_EXISTS(offset, ignore, Pjpm);
// Create a bitmap leaf (special case for Judy1 64-bit only, see usage): Set
// new Index in bitmap, copy an Immed1_15 to the bitmap, and set the parent JP
// EXCEPT jp_DcdPopO, leaving any followup to the caller:
if ((PjlbRaw = j__udyAllocJLB1(Pjpm)) == (Pjlb_t) NULL)
return(-1);
Pjlb = P_JLB(PjlbRaw);
JU_BITMAPSETL(Pjlb, Index);
for (offset = 0; offset < 15; ++offset)
JU_BITMAPSETL(Pjlb, Pjp->jp_1Index[offset]);
// Set jp_DcdPopO including the current pop0; incremented later:
DcdP0 = (Index & cJU_DCDMASK(1)) + 15 - 1;
JU_JPSETADT(Pjp, (Word_t)PjlbRaw, DcdP0, cJU_JPLEAF_B1);
return(1);
}
#endif
// cJU_JPIMMED_[2..7]_[02..15] cases that grow in place or cascade:
//
// (2_01 => [ 2_02 => 2_03 => [ 2_04..07 => ]] LeafL)
#if (defined(JUDY1) || defined(JU_64BIT))
case cJU_JPIMMED_2_02:
#endif
#if (defined(JUDY1) && defined(JU_64BIT))
case cJU_JPIMMED_2_03:
case cJ1_JPIMMED_2_04:
case cJ1_JPIMMED_2_05:
case cJ1_JPIMMED_2_06:
#endif
#if (defined(JUDY1) || defined(JU_64BIT))
JU_IMMSETINPLACE(2, uint16_t *, cJU_JPIMMED_2_02, j__udySearchLeaf2,
JU_INSERTINPLACE);
#endif
#undef OLDPOP1
#if ((defined(JUDY1) && (! defined(JU_64BIT))) || (defined(JUDYL) && defined(JU_64BIT)))
case cJU_JPIMMED_2_03:
#define OLDPOP1 3
#endif
#if (defined(JUDY1) && defined(JU_64BIT))
case cJ1_JPIMMED_2_07:
#define OLDPOP1 7
#endif
#if (defined(JUDY1) || defined(JU_64BIT))
JU_IMMSETCASCADE(2, OLDPOP1, uint16_t *, cJU_JPLEAF2,
JL_LEAF2VALUEAREA, j__udySearchLeaf2,
JU_INSERTCOPY, j__udyAllocJLL2);
#endif
// (3_01 => [ 3_02 => [ 3_03..05 => ]] LeafL)
#if (defined(JUDY1) && defined(JU_64BIT))
case cJU_JPIMMED_3_02:
case cJ1_JPIMMED_3_03:
case cJ1_JPIMMED_3_04:
JU_IMMSETINPLACE(3, uint8_t *, cJU_JPIMMED_3_02, j__udySearchLeaf3,
( run in 1.367 second using v1.01-cache-2.11-cpan-2398b32b56e )