Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/doc/ext/JudyL_3.htm view on Meta::CPAN
marked to <B>NOT</B> point to another Judy array. A <B>JLAP_INVALID</B> flag is
used in the least significant bit(s) of the pointer.
After the flag <B>JLAP_INVALID</B> is removed, it is used as a pointer to the users data.
The <B>Judy.h</B> header file defines <B>JLAP_INVALID</B>.
See code fragment below.
<P>
Note: The current version of <B>Judy.h</B> changed this flag from 0x4 to 0x1
to allow for a <I>malloc()</I> that does not deliver memory on an 8 byte
aligned boundry (such as old versions of valgrind).
<P>
The following example code segment can be used to determine whether or
not a pointer points to another JudyL:
<P>
<PRE>
PValue = (PWord_t)PMultiDimArray;
for (Dim = 0; ;Dim++)
{
if (PValue == (PWord_t)NULL) goto IndexNotFound;
/* Advance to next dimension in array */
JLG(PValue, (Pvoid_t)*PValue, Index[Dim]);
/* Check if pointer to user buffer: */
if (*PValue & JLAP_INVALID)) break;
}
UPointer = (UPointer_t) (*PValue & ~JLAP_INVALID); // mask and cast.
printf("User object pointer is 0x%lx\n", (Word_t) UPointer);
...
</PRE>
<P>
Note: This works because <I>malloc()</I> guarantees to return a pointer
with the least bit(s) == 0x0.
You must remove <B>JLAP_INVALID</B> before using the pointer.
</DL>
<!----------------->
<P>
<DT><A name="JLERR"><B>ERRORS:</B> See: </A><A href="Judy_3.htm#ERRORS">Judy_3.htm#ERRORS</A></DT>
<DD>
<!----------------->
<P>
<DT><B>EXAMPLE</B></DT>
<DD>
Read a series of index/value pairs from the standard input, store
in a JudyL array, and then print out in sorted order.
<P>
<PRE>
#include <stdio.h>
#include <Judy.h>
Word_t Index; // array index
Word_t Value; // array element value
Word_t * PValue; // pointer to array element value
int Rc_int; // return code
Pvoid_t PJLArray = (Pvoid_t) NULL; // initialize JudyL array
while (scanf("%lu %lu", &Index, &Value))
{
JLI(PValue, PJLArray, Index);
If (PValue == PJERR) goto process_malloc_failure;
*PValue = Value; // store new value
}
// Next, visit all the stored indexes in sorted order, first ascending,
// then descending, and delete each index during the descending pass.
Index = 0;
JLF(PValue, PJLArray, Index);
while (PValue != NULL)
{
printf("%lu %lu\n", Index, *PValue));
JLN(PValue, PJLArray, Index);
}
Index = -1;
JLL(PValue, PJLArray, Index);
while (PValue != NULL)
{
printf("%lu %lu\n", Index, *PValue));
JLD(Rc_int, PJLArray, Index);
if (Rc_int == JERR) goto process_malloc_failure;
JLP(PValue, PJLArray, Index);
}
</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="Judy1_3.htm">Judy1(3)</A>,
<A href="JudySL_3.htm">JudySL(3)</A>,
<A href="JudyHS_3.htm">JudyHS(3)</A>,
<BR>
<I>malloc()</I>,
<BR>
<A href="http://judy.sourceforge.net">
http://judy.sourceforge.net</A>,
for more information and Application Notes.
</BODY>
</HTML>
( run in 0.598 second using v1.01-cache-2.11-cpan-39bf76dae61 )