Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/src/JudyCommon/JudyCount.c view on Meta::CPAN
case cJ1_JPIMMED_1_12: IMMABOVE(j__udySearchLeaf1, 12);
case cJ1_JPIMMED_1_13: IMMABOVE(j__udySearchLeaf1, 13);
case cJ1_JPIMMED_1_14: IMMABOVE(j__udySearchLeaf1, 14);
case cJ1_JPIMMED_1_15: IMMABOVE(j__udySearchLeaf1, 15);
#endif
#if (defined(JUDY1) || defined(JU_64BIT))
case cJU_JPIMMED_2_02: IMMABOVE(j__udySearchLeaf2, 2);
case cJU_JPIMMED_2_03: IMMABOVE(j__udySearchLeaf2, 3);
#endif
#if (defined(JUDY1) && defined(JU_64BIT))
case cJ1_JPIMMED_2_04: IMMABOVE(j__udySearchLeaf2, 4);
case cJ1_JPIMMED_2_05: IMMABOVE(j__udySearchLeaf2, 5);
case cJ1_JPIMMED_2_06: IMMABOVE(j__udySearchLeaf2, 6);
case cJ1_JPIMMED_2_07: IMMABOVE(j__udySearchLeaf2, 7);
#endif
#if (defined(JUDY1) || defined(JU_64BIT))
case cJU_JPIMMED_3_02: IMMABOVE(j__udySearchLeaf3, 2);
#endif
#if (defined(JUDY1) && defined(JU_64BIT))
case cJ1_JPIMMED_3_03: IMMABOVE(j__udySearchLeaf3, 3);
case cJ1_JPIMMED_3_04: IMMABOVE(j__udySearchLeaf3, 4);
case cJ1_JPIMMED_3_05: IMMABOVE(j__udySearchLeaf3, 5);
case cJ1_JPIMMED_4_02: IMMABOVE(j__udySearchLeaf4, 2);
case cJ1_JPIMMED_4_03: IMMABOVE(j__udySearchLeaf4, 3);
case cJ1_JPIMMED_5_02: IMMABOVE(j__udySearchLeaf5, 2);
case cJ1_JPIMMED_5_03: IMMABOVE(j__udySearchLeaf5, 3);
case cJ1_JPIMMED_6_02: IMMABOVE(j__udySearchLeaf6, 2);
case cJ1_JPIMMED_7_02: IMMABOVE(j__udySearchLeaf7, 2);
#endif
// ----------------------------------------------------------------------------
// OTHER CASES:
default: JU_SET_ERRNO_NONNULL(Pjpm, JU_ERRNO_CORRUPT); return(C_JERR);
} // switch on JP type
/*NOTREACHED*/
} // j__udy1LCountSM()
// ****************************************************************************
// J U D Y C O U N T L E A F B 1
//
// This is a private analog of the j__udySearchLeaf*() functions for counting
// in bitmap 1-byte leaves. Since a bitmap leaf describes Indexes digitally
// rather than linearly, this is not really a search, but just a count of the
// valid Indexes == set bits below or including Index, which should be valid.
// Return the "offset" (really the ordinal), 0 .. Pop1 - 1, of Index in Pjll;
// if Indexs bit is not set (which should never happen, so this is DEBUG-mode
// only), return the 1s-complement equivalent (== negative offset minus 1).
//
// Note: The source code for this function looks identical for both Judy1 and
// JudyL, but the JU_JLB_BITMAP macro varies.
//
// Note: For simpler calling, the first arg is of type Pjll_t but then cast to
// Pjlb_t.
FUNCTION static int j__udyCountLeafB1(
const Pjll_t Pjll, // bitmap leaf, as Pjll_t for consistency.
const Word_t Pop1, // Population of whole leaf.
const Word_t Index) // to which to count.
{
Pjlb_t Pjlb = (Pjlb_t) Pjll; // to proper type.
Word_t digit = Index & cJU_MASKATSTATE(1);
Word_t findsub = digit / cJU_BITSPERSUBEXPL;
Word_t findbit = digit % cJU_BITSPERSUBEXPL;
int count; // in leaf through Index.
long subexp; // for stepping through subexpanses.
// COUNT UPWARD:
//
// The entire bitmap should fit in one cache line, but still try to save some
// CPU time by counting the fewest possible number of subexpanses from the
// bitmap.
#ifndef NOSMARTJLB // enable to turn off smart code for comparison purposes.
if (findsub < (cJU_NUMSUBEXPL / 2))
{
#ifdef SMARTMETRICS
++jlb_upward;
#endif
count = 0;
for (subexp = 0; subexp < findsub; ++subexp)
{
count += ((JU_JLB_BITMAP(Pjlb, subexp) == cJU_FULLBITMAPL) ?
cJU_BITSPERSUBEXPL :
j__udyCountBitsL(JU_JLB_BITMAP(Pjlb, subexp)));
}
// This count includes findbit, which should be set, resulting in a base-1
// offset:
count += j__udyCountBitsL(JU_JLB_BITMAP(Pjlb, findsub)
& JU_MASKLOWERINC(JU_BITPOSMASKL(findbit)));
DBGCODE(if (! JU_BITMAPTESTL(Pjlb, digit)) return(~count);)
assert(count >= 1);
return(count - 1); // convert to base-0 offset.
}
#endif // NOSMARTJLB
// COUNT DOWNWARD:
//
// Count the valid Indexes above or at Index, and subtract from Pop1.
#ifdef SMARTMETRICS
++jlb_downward;
#endif
( run in 1.011 second using v1.01-cache-2.11-cpan-39bf76dae61 )