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!