Alien-Judy

 view release on metacpan or  search on metacpan

src/judy-1.0.5/doc/ext/Judy1_3.htm  view on Meta::CPAN

(Start with <B>Index</B> = 0 to find the first index in the
array.)  <B>J1F()</B> is typically used to <I>begin</I> a
sorted-order scan of the indexes present in a Judy1 array.
<P>
<DT><A name="J1N"><B>J1N(Rc_int, PJ1Array, Index);</B></A> // <A href="Judy1_funcs_3.htm#Judy1Next">Judy1Next()</A></DT>
<DD>
Search (exclusive) for the next index present that is
greater than the passed <B>Index</B>.
<B>J1N()</B> is typically used to <I>continue</I> a
sorted-order scan of the indexes present
in a Judy1 array, or to locate a "neighbor" of a given index.
<P>
<DT><A name="J1L"><B>J1L(Rc_int, PJ1Array, Index);</B></A> // <A href="Judy1_funcs_3.htm#Judy1Last">Judy1Last()</A></DT>
<DD>
Search (inclusive) for the last index present that is equal
to or less than the passed <B>Index</B>.  (Start with
<B>Index</B> = -1, that is, all ones, to find the last index
in the array.)  <B>J1L()</B> is typically used to <I>begin</I>
a reverse-sorted-order scan
of the indexes present in a Judy1 array.
<P>
<DT><A name="J1P"><B>J1P(Rc_int, PJ1Array, Index);</B></A> // <A href="Judy1_funcs_3.htm#Judy1Prev">Judy1Prev()</A></DT>
<DD>
Search (exclusive) for the previous index present that is
less than the passed <B>Index</B>.  <B>J1P()</B> is typically
used to <I>continue</I> a reverse-sorted-order scan of the indexes
present in a Judy1 array, or to locate a "neighbor" of a given index.
<P>
<DT><A name="J1FE"><B>J1FE(Rc_int, PJ1Array, Index);</B></A> // <A href="Judy1_funcs_3.htm#Judy1FirstEmpty">Judy1FirstEmpty()</A></DT>
<DD>
Search (inclusive) for the first absent index that is equal to
or greater than the passed <B>Index</B>.  (Start with
<B>Index</B> = 0 to find the first index absent in the array.)
<P>
<DT><A name="J1NE"><B>J1NE(Rc_int, PJ1Array, Index);</B></A> // <A href="Judy1_funcs_3.htm#Judy1NextEmpty">Judy1NextEmpty()</A></DT>
<DD>
Search (exclusive) for the next absent index that is
greater than the passed <B>Index</B>.
<P>
<DT><A name="J1LE"><B>J1LE(Rc_int, PJ1Array, Index);</B></A> // <A href="Judy1_funcs_3.htm#Judy1LastEmpty">Judy1LastEmpty()</A></DT>
<DD>
Search (inclusive) for the last absent index that is
equal to or less than the passed <B>Index</B>.
(Start with <B>Index</B> = -1 to find the last index
absent in the array.)
<P>
<DT><A name="J1PE"><B>J1PE(Rc_int, PJ1Array, Index);</B></A> // <A href="Judy1_funcs_3.htm#Judy1PrevEmpty">Judy1PrevEmpty()</A></DT>
<DD>
Search (exclusive) for the previous absent index that is
less than the passed <B>Index</B>.
</DL>
<!----------------->
<P>
<DT><A name="J1ERR"><B>ERRORS:</B> See: </A><A href="Judy_3.htm#ERRORS">Judy_3.htm#ERRORS</A></DT>
<DD>
<!----------------->
<P>
<DT><A name="J1EX"><B>EXAMPLE</B></A></DT>
<DD>
In the following example, errors in the <B>J1S()</B> or <B>J1U()</B> calls
go to a user-defined procedure, process_malloc_failure.  This is not needed
when you use the default <B>JUDYERROR()</B> macro, since the default causes
your program to exit on all failures,
including <I>malloc()</I> failure.
<P>
<PRE>
#include &lt;stdio.h&gt;
#include &lt;Judy.h&gt;

int main()                       // Example program of Judy1 macro APIs
{
   Word_t Index;                 // index (or key)
   Word_t Rcount;                // count of indexes (or bits set)
   Word_t Rc_word;               // full word return value
   int    Rc_int;                // boolean values returned (0 or 1)

   Pvoid_t PJ1Array = (Pvoid_t) NULL; // initialize Judy1 array

   Index = 123456;
   J1S(Rc_int, J1Array, Index);  // set bit at 123456
   if (Rc_int == JERR) goto process_malloc_failure;
   if (Rc_int == 1) printf("OK - bit successfully set at %lu\n", Index);
   if (Rc_int == 0) printf("BUG - bit already set at %lu\n", Index);

   Index = 654321;
   J1T(Rc_int, J1Array, Index);  // test if bit set at 654321
   if (Rc_int == 1) printf("BUG - set bit at %lu\n", Index);
   if (Rc_int == 0) printf("OK - bit not set at %lu\n", Index);

   J1C(Rcount, J1Array, 0, -1);  // count all bits set in array
   printf("%lu bits set in Judy1 array\n", Rcount);

   Index = 0;
   J1F(Rc_int, J1Array, Index);  // find first bit set in array
   if (Rc_int == 1) printf("OK - first bit set is at %lu\n", Index);
   if (Rc_int == 0) printf("BUG - no bits set in array\n");

   J1MU(Rc_word, J1Array);       // how much memory was used?
   printf("%lu Indexes used %lu bytes of memory\n", Rcount, Rc_word);

   Index = 123456;
   J1U(Rc_int, J1Array, Index);  // unset bit at 123456
   if (Rc_int == JERR) goto process_malloc_failure;
   if (Rc_int == 1) printf("OK - bit successfully unset at %lu\n", Index);
   if (Rc_int == 0) printf("BUG - bit was not set at %lu\n", Index);

   return(0);
}
</PRE>
<!----------------->
<P>
<DT><B>AUTHOR</B></DT>
<DD>
Judy was invented by Doug Baskins and implemented by Hewlett-Packard.
<!----------------->
<P>
<DT><B>SEE ALSO</B></DT>
<DD>
<A href="Judy_3.htm">Judy(3)</A>,
<A href="JudyL_3.htm">JudyL(3)</A>,
<A href="JudySL_3.htm">JudySL(3)</A>,
<A href="JudyHS_3.htm">JudyHS(3)</A>,
<BR>
<I>malloc()</I>,
<BR>
the Judy website,
<A href="http://judy.sourceforge.net">
http://judy.sourceforge.net</A>,
for more information and Application Notes.
</DL>
</BODY>
</HTML>



( run in 1.618 second using v1.01-cache-2.11-cpan-140bd7fdf52 )