Programming with Judy

Using Judy
Using JudyL
Chapter 3 39
// COUNT THE NUMBER OF ELEMENTS IN THE JUDYL ARRAY
// IE. COUNT THE NUMBER OF UNIQUE RANDOM NUMBERS
STARTTm;
unique_nums = JudyLCount(PJArray, 0, ~0L, &JError);
ENDTm;
(void) printf("\nThere were %ld unique random numbers generated\n",
unique_nums);
(void) printf("It took %.3f uSec to count them in the Judy array.\n",
DeltaUSec);
// FIND HOW MANY NUMBERS WERE GENERATED ONCE, TWICE, ...
//
// Create a new JudyL array where the index is the count from PJArray
// and the value is a count of the number of elements with that count.
if (unique_nums != num_vals)
{
(void) puts("\nLooping through the entire Judy array to create a");
(void) puts("new Judy counting array (PJCountArray in the source code)");
(void) puts("...");
STARTTm;
for (Index = 0L,
PValue = (ulong_t *)JudyLFirst(PJArray, &Index, &JError);
PValue;
PValue = (ulong_t *)JudyLNext(PJArray, &Index, &JError))
{
if ((PGenCount = (ulong_t *)JudyLIns(&PJCountArray, *PValue, &JError)) == PJERR)
{
JUDY_ERROR(JError); // exits