~ubuntu-branches/ubuntu/breezy/judy/breezy

« back to all changes in this revision

Viewing changes to src/apps/demo/interL.c

  • Committer: Bazaar Package Importer
  • Author(s): Theodore Y. Ts'o
  • Date: 2004-01-17 00:04:53 UTC
  • Revision ID: james.westby@ubuntu.com-20040117000453-d5sj6uoon2v1g4gf
Tags: upstream-0.0.4
ImportĀ upstreamĀ versionĀ 0.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <Judy.h>
 
3
 
 
4
main()  // Simple JudyL demo, see "run_demo" script; @(#) $Revision: 4.4 $
 
5
{
 
6
    Pvoid_t  Parray = (Pvoid_t) NULL;           // empty JudyL array.
 
7
    Word_t * Pvalue;                            // value for one index.
 
8
    char     line[BUFSIZ];                      // input line.
 
9
    Word_t   index;                             // in JudyL array.
 
10
 
 
11
    printf("Interactive Judy demo program to input, sort, and list numbers.\n"
 
12
           "Enter a number:  ");  // fflush(stdout); ?
 
13
 
 
14
    while (fgets(line, BUFSIZ, stdin))          // input.
 
15
    {
 
16
        index = strtoul(line, NULL, 0);         // note: bad input => 0.
 
17
        JLI(Pvalue, Parray, index);             // insert index in JudyL array.
 
18
        ++(*Pvalue);                            // count duplicates.
 
19
 
 
20
        printf("       Index  Dups\n");         // print all saved indexes:
 
21
        index = 0;                              // start search at zero.
 
22
        JLF(Pvalue, Parray, index);             // find first saved index.
 
23
 
 
24
        while (Pvalue != NULL)
 
25
        {
 
26
            printf("%12lu %5lu\n", index, *Pvalue);
 
27
            JLN(Pvalue, Parray, index);         // find next saved index.
 
28
        }
 
29
        printf("Next:  ");  // fflush(stdout); ?
 
30
    }
 
31
}