Rauan et al,
> I want to create kind of associative array or hashmap and due to lack
> of simple examples (quickstarts)...
Sorry about that.
> ...don't know what type of judy array to use, and how to implement it.
I'll try to help.
> My task is: I have unique string hash, e.g. "asdczxtdfdgk" (if it
> does make sense, length of hash is persistent). By this hash i want
> to get object/struct or array of values.
>
> Could you provide simple example?
Yes, but let's talk about your hash string first. Why use a hash at all
with libJudy, when it takes CPU time to compute the hash key, and
there's some risk of collision no matter how good is your algorithm?
Let's say instead that you have an actual C string as your key/index,
and you want to map it to a malloc()'d object of whatever kind you like.
The "liberating" concept here is that storing a very long string can
still be very fast and cheap. The code (using the macros and ignoring
error handling) looks like this:
mydata_pt mydatap; // your pre-malloc()'d data record.
char * index; // a key to save.
char index2[MAXSIZE]; // for traversing JudySL array.
Pvoid_t jsl = NULL; // the JudySL array.
PWord_t valuep; // current value.
PWord_t rcw; // for JSLFA().
// Save a value:
...
JSLI(valuep, jsl, index);
*valuep = (PWord_t) mydatap;
...
// Traverse all keys (strings) in simple-sort order:
index2[0] = '\0';
JSLF(valuep, jsl, index2);
while (valuep != NULL)
{
DoSomethingWith(index2, (mydata_pt) *valuep);
JSLN(valuep, jsl, index2);
}
// Erase array; must visit and free() each value record first:
// (Not necessary if the data fits directly in the value word.)
index2[0] = '\0';
JSLF(valuep, jsl, index2);
while (valuep != NULL)
{
free((void *) (*valuep));
JSLN(valuep, jsl, index2);
}
JSLFA(rcw, jsl);
----------------------
Now, does that help?
Alan Silverstein
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Judy-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/judy-devel