Well, you are not the first. Your problem below seems to be that the "&" is not needed on the
Judy functions that read (not insert or delete or modify an Index in a Judy array). The
"PPValue = JudySLGet( & PArray, needle, 0 );"
in your below example should be:
"PPValue = JudySLGet(PArray, needle, 0 );"
(I will nit pick on the 0 should be a PJE0 -- but
C doesn's care, maybe C++ does? C++ changed the sematics of "void *" since Judy was written).
Another nit: I use PValue = (cast_t *)JudyG... when Value is a scaler, and PPValue = (cast_t **) JudyG...
when Value is a pointer. This helps me with my confused mind.
Are you sure you need multiple JudySL() arrays?
The main reason that the Insert/Delete/Free functions need the "&" in front of the array pointer is
to allow the array to be allocated from a NULL pointer (Judy needs it's address to modify the (single)
direct pointer to the array in RAM). I realize that "pointer to pointer" is very confusing to the human
mind, but this is the only way (in C) that this can be done -- except hidden in a Macro).
On perhaps something a more esoteric, the ability a Judy array to be initialized from
a NULL pointer, plus the fact that every insertion to Judy returns a pointer to a "NULL"
means that a virtual infinite amount of memory can be allocated starting with a NULL pointer.
In other words think of a NULL pointer as a JudyL or JudySL array and then think of what
they return as the same etc. The Judy Macros were a perhaps poor attempt to hide this problem from
the programmer -- as in:
JLI(PValue, PArray, Index); V.S. PValue = (Value_t *)JudyLIns(&PArray, Index, NULL);
(The macro JLI() also allows you to define many error handing methods, but to my
knowledge, nobody ever uses this powerful feature).
I have labored for years about the "&" and what is really important. I am working on a new version
of Judy and beginning to think of whether to change the Judy name and API. All comments
are welcome from all.
BTW, JudySL is actually implemented as a JudyL array of JudyL arrays with the depth
extended to support the length of the string passed to JudySL. This is the secondary
reason for the "&" in &PArray -- the small JudyL(1,2,3 elements) arrays need to be very
Doug Baskins <email@example.com>
----- Original Message ----
From: Len D'Alberti <firstname.lastname@example.org>
Sent: Thursday, May 22, 2008 11:08:47 PM
Subject: array of JudySL arrays
hi there - I've been playing with JudySL for a few days now and it would seem to fit in perfectly with a project I am currently working on.
I need help, though, understanding how to create an array of JudySL arrays, so that I can go from this:
void * PArray = (Pvoid_t) NULL;
PPValue = JudySLIns (& PArray, record, &JError);
PPValue = JudySLGet( & PArray, needle, 0 );
(which works great when I'm looking at only one file and one JudySL array)
to something like this:
void * PArray
PValue = JudySLIns (& PArray[i], record, &JError);
PPValue = JudySLGet( & PArray[i], needle, 0 );
which doesn't appear to work (fyi: I need to be able to search a bunch of files and determine which file where it was found).
I suspect that this might be more of a C question, since I'm not as well versed in C as I'd like to be.
what am I missing? hope I'm not doing something incredibly stupid...