From: Schaeferhaus <sch...@ya...> - 2009-05-20 08:50:55
|
Yes, the macros are really confusing, but the authors are still insisting using the macro interface instead of direct calls. I hope this will change in the next version. The macros are NOT FASTER. Judy is VERY VERY easy to use without the macro calls. Simply ignore the macros and the abstract types. Hier what i'm ALWAYS using (i mean using without thinking). - ALWAYS declare the Judy arrays as "void *" . Ex. void *myjudy - ALWAYS declare the PVAL value as "Word_t *" . Ex. Word_t *pval - Call the Judy changing functions by reference (JudyXXIns,JudyXXDel,JudyXXFreeArray) Ex. pval = JudySLIns(&myjudy, mystring, NULL). if(!pval) { printf("Not enough memory"); exit(-1); } if(!*pval) { printf("key is new"); *pval = 1; } else { printf("key is duplicate.Num=%d", *pval); *pval = *pval + 1; } - call the GET,PREV,NEXT functions by value. Ex. pval = JudySLGet(myjudy, mystring, NULL). if(!pval) printf("Key not not found"); Hier an example of a sparse array of array (Try this with the macros!!) #include <Judy.h> void *judy = NULL; Word_t *px,*py; unsigned x,y; // insert x = 3; y = 5; if( (px = JudyLIns(&judy, x, NULL)) && (py = JudyLIns(px, y, NULL)) ) *py = 15; if(!px || !py) { printf("Not enough memory\n"); exit(-1); } ... ... // print for(x=0,px = JudyLFirst(judy, &x, NULL); px; px = JudyLNext(judy, &x, NULL)) for(y=0,py = JudyLFirst(*px, &y, NULL); py; py = JudyLNext(*px, &y, NULL)) printf("x=%u, y=%u -> cell value=%u\n", x, y, *py); |