1*2ab53118Sbostic /*-
2*2ab53118Sbostic * %sccs.include.proprietary.c%
3*2ab53118Sbostic */
4*2ab53118Sbostic
5037c2ecdStut #ifndef lint
6*2ab53118Sbostic static char sccsid[] = "@(#)inv6.c 4.3 (Berkeley) 04/18/91";
7*2ab53118Sbostic #endif /* not lint */
8037c2ecdStut
9037c2ecdStut #include <stdio.h>
10037c2ecdStut #include <assert.h>
11037c2ecdStut
whash(ft,fa,fb,nhash,iflong,ptotct,phused)12037c2ecdStut whash(ft, fa, fb, nhash, iflong, ptotct, phused)
13037c2ecdStut FILE *fa, *fb, *ft;
14037c2ecdStut int nhash, *phused;
15037c2ecdStut long *ptotct;
16037c2ecdStut {
17037c2ecdStut char line[100];
18037c2ecdStut int hash = 0, hused = 0;
19037c2ecdStut long totct = 0L;
20037c2ecdStut int ct = 0;
21037c2ecdStut long point;
22037c2ecdStut long opoint = -1;
23037c2ecdStut int m;
24037c2ecdStut int k;
25037c2ecdStut long lp;
26037c2ecdStut long *hpt;
271a17a1d3Sralph int *hfreq;
28037c2ecdStut
291a17a1d3Sralph hpt = (long *) calloc (nhash+1, sizeof(*hpt));
30037c2ecdStut _assert (hpt != NULL);
311a17a1d3Sralph hfreq = (int *) calloc (nhash, sizeof(*hfreq));
32037c2ecdStut _assert (hfreq != NULL);
33037c2ecdStut hpt[0] = 0;
34037c2ecdStut lp= 0;
35037c2ecdStut while (fgets(line, 100, ft))
36037c2ecdStut {
37037c2ecdStut totct++;
38037c2ecdStut sscanf(line, "%d %ld", &k, &point);
39037c2ecdStut if (hash < k)
40037c2ecdStut {
41037c2ecdStut hused++;
42037c2ecdStut if (iflong) putl(-1L, fb);
43037c2ecdStut else putw(-1, fb);
44037c2ecdStut hfreq[hash]=ct;
45037c2ecdStut while (hash<k)
46037c2ecdStut {
47037c2ecdStut hpt[++hash] = lp;
48037c2ecdStut hfreq[hash] = 0;
49037c2ecdStut }
50037c2ecdStut hpt[hash] = lp += iflong? sizeof(long) : sizeof(int);
51037c2ecdStut opoint= -1;
52037c2ecdStut ct=0;
53037c2ecdStut }
54037c2ecdStut if (point!=opoint)
55037c2ecdStut {
56037c2ecdStut if (iflong)
57037c2ecdStut putl(opoint=point, fb);
58037c2ecdStut else
59037c2ecdStut putw( (int)(opoint=point), fb);
60037c2ecdStut lp += iflong? sizeof(long) : sizeof(int);
61037c2ecdStut ct++;
62037c2ecdStut }
63037c2ecdStut }
64037c2ecdStut if (iflong) putl(-1L, fb);
65037c2ecdStut else putw(-1,fb);
66037c2ecdStut while (hash<nhash)
67037c2ecdStut hpt[++hash]=lp;
68037c2ecdStut fwrite(&nhash, sizeof(nhash), 1, fa);
69037c2ecdStut fwrite(&iflong, sizeof(iflong), 1, fa);
70037c2ecdStut fwrite(hpt, sizeof(*hpt), nhash, fa);
71037c2ecdStut fwrite (hfreq, sizeof(*hfreq), nhash, fa);
72037c2ecdStut *ptotct = totct;
73037c2ecdStut *phused = hused;
74037c2ecdStut }
75037c2ecdStut
putl(ll,f)76037c2ecdStut putl(ll, f)
77037c2ecdStut long ll;
78037c2ecdStut FILE *f;
79037c2ecdStut {
80037c2ecdStut putw(ll, f);
81037c2ecdStut }
82037c2ecdStut
83037c2ecdStut long
getl(f)84037c2ecdStut getl(f)
85037c2ecdStut FILE *f;
86037c2ecdStut {
87037c2ecdStut return(getw(f));
88037c2ecdStut }
89