Programming with Judy
Using Judy
Using JudySL
Chapter 3 45
JudySL sorting
example
You can find the code for this example and others on the Judy web site:
http://devresource.hp.com/judy/
// JudySort.c
// Judy demonstration code: Judy equivalent of sort -u. While Judy is not
// primarily intended as a sorting algorithm, in many cases it's faster to
// store values in a Judy array and read them back in sorted order than to sort
// them using standard algorithms.
//
// Usage: <program> <file-to-sort>
//
// Code and comments are included if you want to modify the program to output
// duplicates as an exercise.
//
// Note: If an input line is longer than BUFSIZ, it's broken into two or more
// lines.
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "Judy.h"
main (int argc, char ** argv)
{
Pvoid_t PJArray = (Pvoid_t) NULL; // Judy array.
PPvoid_t PPValue; // Judy array element.
char Index [BUFSIZ]; // string to sort.
char * Pc; // place in Index.
FILE * fpin; // to read file.
JError_t JError; // Judy error structure