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.
> *((Word_t*)PValue) = I;
> }
>
> uint64_t Retrieved;
> for (uint64_t I=0; I<10; I++) //Confirm that the stored values match each
> string's index
> {
> char *String_Key = Strings[I];
> JSLG(PValue, JudySLRoot, (uint8_t*)String_Key);
> Retrieved = *((Word_t*)PValue);
> }
>
> uint8_t *Retrieved_String=NULL;
> PValue = NULL;
> JSLF(PValue, JudySLRoot, Retrieved_String);
Here is your bug. JSLF does NOT retrieve the first element
in the array. It is poorly named. First does NOT mean
what you think. It means
satisfying >=
whereas Next means
satisfying >
So your initial value of RetrievedString is incorrect, it must be done
like this:
uint8_t * RetrievedString = (RetrievedString *) calloc(20000);
It must be a pointer to storage initialised with at least on leading
byte of value zero.
Judy is highly consistent and logical in its interface.
It has two problems at the C API level: the use of void *, Word_t*
etc is super unsafe, especially in C. This is a stupidity in C
in particular (not in Judy).
The second problem is that First doesn't mean first in the
array it means >= the key. 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.
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Judy-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/judy-devel