Programming with Judy

Example of a Multi-dimensional Array
Concepts
Chapter 4 49
4 Example of a Multi-dimensional
Array
The JudySLGet and JudySLIns functions shown in this chapter
illustrate a multi-dimensional JudyL array. This code is the proof of
concept code for the Judy Version 4.0 functions: JudySLGet() and
JudySLIns(). Although it is similar to the current JudySL, this code
should not be used with released JudySL functions.
Concepts
Copy each null-terminated string (index) into an array of N words
(ulong_t's) with zero-padding in the last word if necessary. Use each word
in this array as a level index in a multi-dimensional Judy array. For
example, consider these two input strings:
"abcdefghijk"
"abcdefgk"
These are used as if they are arrays of 32- bit integers with the following
keys:
"abcd", "efgh", "ijk0"
"abcd", "efgk", "0000"
Since a JudyL data element has both a key and a value, we can use the
value to either point to another Judy array, or if the key contains a
NULL, we can use the value area for user data. With this logic, the two
strings above produce four Judy arrays:
Notes:
Only 32 bit versions of the WORDCPY macros are shown in this
example.
You can find the code for this example and others on the Judy web
site: http://devresource.hp.com/judy/