File: CheckDupLines.c

package info (click to toggle)
judy 1.0.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,540 kB
  • ctags: 2,566
  • sloc: ansic: 24,975; sh: 9,565; makefile: 394
file content (44 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#include <Judy.h>

//#include "JudyHS.h" 			// for Judy.h without JudyHS*()

// By Doug Baskins Apr 2004 - for JudyHS man page

#define MAXLINE 1000000			/* max length of line */
char      Index[MAXLINE];            	// string to check

int     // Usage:  CheckDupLines < file
main()
{
    Pvoid_t   PJArray = (PWord_t)NULL;  // Judy array.
    PWord_t   PValue;                   // Judy array element.
    Word_t    Bytes;                    // size of JudyHS array.
    Word_t    LineNumb = 0;		// current line number
    Word_t    Dups = 0;			// number of duplicate lines

    while (fgets(Index, MAXLINE, stdin) != (char *)NULL)
    {
	LineNumb++;			// line number

//	store string into array
        JHSI(PValue, PJArray, Index, strlen(Index)); 
        if (*PValue)			// check if duplicate
	{
            Dups++;			// yes, count
	    printf("Duplicate lines %lu:%lu:%s", *PValue, LineNumb, Index);
	}
	else
	{
	    *PValue = LineNumb;		// store Line number
	}
    }
    printf("%lu Duplicates, free JudyHS array of %lu Lines\n", 
		    Dups, LineNumb - Dups);
    JHSFA(Bytes, PJArray);              // free array
    printf("The JudyHS array allocated %lu bytes of memory\n", Bytes);
    return (0);
}