Hi,
it is sade that there are not so many examples showing how powerfull the judy
arrays library is.
Range/Interval (disjoint sets) searching with judy arrays is a very good
example
showing the advantage of
the judy arrays over hash based libraries.
You can store the start value of the set in the Judy array and the end value in
the corresponding pvalue.
Note: i'm not using the confusing macros and the abstract types (except Word_t).
Programing with judy can be so simple...
#include <Judy.h>
//Insert interval
int itvins( void **judy, Word_t begin, Word_t end ) {
void *pval = JudyLIns(judy, begin, NULL); if(!pval) return -1;
*pval = end;
return 0;
}
//Search Interval
Word_t itvget( void *judy, Word_t *begin) {
Word_t val = *begin;
void *pval = JudyLPrev(judy, begin, NULL) ;
if(pval && val >= begin && val <= *pval) return *pval;
return -1;
}
main()
{
void *judy = NULL;
itvins(&judy, 0,8);
itvins(&judy, 16,24);
// ...
// search for any point in range (4,20)
Word_t begin=4, end;
if((end = itvget(judy, &begin)) == -1) itvins(&judy, 4,20);
}
.....et voila!
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Judy-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/judy-devel