Thanks.  John's answer fixes the crashing loop.  I still have the access violation in 64-bit mode when populating the tree, though.

On 10/23/2012 7:16 PM, john skaller wrote:
On 24/10/2012, at 10:26 AM, Tim Margheim wrote:
Here's the code:
--------------------------
    Pvoid_t JudySLRoot = NULL;   // main JudySL array
    Pvoid_t  PValue = NULL;         // pointer to JudySL array value
    char *Strings[11] = {"zoo", "ark", "Zed", "Ate", "basdfahsdfkjashdflkjashdflkjahsljkhfeiuahslfkje", "model", "Man", "fire", "f.re", "quorum" };

    for (uint64_t I=0; I<10; I++) //map each string to its index in the Strings array
    {
        char *String_Key = Strings[I];
        JSLI(PValue, JudySLRoot, (uint8_t*)String_Key);
I think it best NOT to use the macros. It's too hard to figure out
what's going on. JSLI here expects PValue to be an lvalue.
I did start using the functions, but when I hit the access violation, I decided to try the macros.  That didn't fix it, but I didn't get around to changing it back to functions.

At any rate, PValue is an lvalue, isn't it?  So I still need to figure out why it works properly in 32-bit, but hits an access violation in 64-bit.  Or am I missing something?

Here is your bug. JSLF does NOT retrieve the first element
in the array. 
[...]
So you have 5 search  operators:

	>= > == < <=

ALL of which require a valid input key. The names First,
Next, Get, Prev, Last, are a bit unconventional
(Ge, Gt, Eq, Lt, Le) would have been better. But they're just
names, the actual C interface is perfect.
Ah, thanks for clearing that up.  So to find the first element, I should be passing in "" as the key, and it will end up being replaced by the first key value >= to "".  Then to iterate through all the elements of the tree, I loop using the Next function/macro.

How large should I make the buffer?  Is there a maximum size that Judy has for a key value--and I should use that?  Or should I define my own maximum size for keys on my tree, and use that?

Anyway, I tried this, and the loop now works as I had intended:

    uint8_t Retrieved_String[100]={0}; //big enough for my test strings
    PValue = NULL;
    JSLF(PValue, JudySLRoot, Retrieved_String); //start by looking up the first key that is >= ""
    while (PValue!=NULL) //Iterate through the table.
    {
        Retrieved = *((Word_t*)PValue);
        JSLN(PValue, JudySLRoot, Retrieved_String);
    }

Anyway, I was wrongly assuming that I was passing in a uint8_t* which would end up pointing to an already-existing buffer with the key value.  But of course, Judy doesn't store a buffer with the key value; also, if that was the way the function was designed, I would've had to pass in a const uint8_t* to prevent me from modifying the stored buffer.  Also, the parameter would actually have to be either a const uint8_t*&, or a const uint8_t**, so that the function could change the pointer's value.

If I'd payed closer attention to the function parameters, I could have figured it out.


---
Tim Margheim
Neuric Technologies, LLC