xref: /csrg-svn/old/refer/inv/inv6.c (revision 12296)
1*12296Stut #ifndef lint
2*12296Stut static char *sccsid = "@(#)inv6.c	4.1 (Berkeley) 05/06/83";
3*12296Stut #endif
4*12296Stut 
5*12296Stut #include <stdio.h>
6*12296Stut #include <assert.h>
7*12296Stut 
8*12296Stut whash(ft, fa, fb, nhash, iflong, ptotct, phused)
9*12296Stut FILE *fa, *fb, *ft;
10*12296Stut int nhash, *phused;
11*12296Stut long *ptotct;
12*12296Stut {
13*12296Stut 	char line[100];
14*12296Stut 	int hash = 0, hused = 0;
15*12296Stut 	long totct = 0L;
16*12296Stut 	int ct = 0;
17*12296Stut 	long point;
18*12296Stut 	long opoint = -1;
19*12296Stut 	int m;
20*12296Stut 	int k;
21*12296Stut 	long lp;
22*12296Stut 	long *hpt;
23*12296Stut 	int *hfreq = NULL;
24*12296Stut 
25*12296Stut 	hpt = calloc (nhash+1, sizeof(*hpt));
26*12296Stut 	_assert (hpt != NULL);
27*12296Stut 	hfreq = calloc (nhash, sizeof(*hfreq));
28*12296Stut 	_assert (hfreq !=NULL);
29*12296Stut 	hpt[0] = 0;
30*12296Stut 	lp= 0;
31*12296Stut 	while (fgets(line, 100, ft))
32*12296Stut 	{
33*12296Stut 		totct++;
34*12296Stut 		sscanf(line, "%d %ld", &k, &point);
35*12296Stut 		if (hash < k)
36*12296Stut 		{
37*12296Stut 			hused++;
38*12296Stut 			if (iflong) putl(-1L, fb);
39*12296Stut 			else putw(-1, fb);
40*12296Stut 			hfreq[hash]=ct;
41*12296Stut 			while (hash<k)
42*12296Stut 			{
43*12296Stut 				hpt[++hash] = lp;
44*12296Stut 				hfreq[hash] = 0;
45*12296Stut 			}
46*12296Stut 			hpt[hash] = lp += iflong? sizeof(long) : sizeof(int);
47*12296Stut 			opoint= -1;
48*12296Stut 			ct=0;
49*12296Stut 		}
50*12296Stut 		if (point!=opoint)
51*12296Stut 		{
52*12296Stut 			if (iflong)
53*12296Stut 				putl(opoint=point, fb);
54*12296Stut 			else
55*12296Stut 				putw( (int)(opoint=point), fb);
56*12296Stut 			lp += iflong? sizeof(long) : sizeof(int);
57*12296Stut 			ct++;
58*12296Stut 		}
59*12296Stut 	}
60*12296Stut 	if (iflong) putl(-1L, fb);
61*12296Stut 	else putw(-1,fb);
62*12296Stut 	while (hash<nhash)
63*12296Stut 		hpt[++hash]=lp;
64*12296Stut 	fwrite(&nhash, sizeof(nhash), 1, fa);
65*12296Stut 	fwrite(&iflong, sizeof(iflong), 1, fa);
66*12296Stut 	fwrite(hpt, sizeof(*hpt), nhash, fa);
67*12296Stut 	fwrite (hfreq, sizeof(*hfreq), nhash, fa);
68*12296Stut 	*ptotct = totct;
69*12296Stut 	*phused = hused;
70*12296Stut }
71*12296Stut 
72*12296Stut putl(ll, f)
73*12296Stut long ll;
74*12296Stut FILE *f;
75*12296Stut {
76*12296Stut 	putw(ll, f);
77*12296Stut }
78*12296Stut 
79*12296Stut long
80*12296Stut getl(f)
81*12296Stut FILE *f;
82*12296Stut {
83*12296Stut 	return(getw(f));
84*12296Stut }
85