112296Stut #ifndef lint 2*17679Sralph static char *sccsid = "@(#)inv6.c 4.2 (Berkeley) 01/09/85"; 312296Stut #endif 412296Stut 512296Stut #include <stdio.h> 612296Stut #include <assert.h> 712296Stut 812296Stut whash(ft, fa, fb, nhash, iflong, ptotct, phused) 912296Stut FILE *fa, *fb, *ft; 1012296Stut int nhash, *phused; 1112296Stut long *ptotct; 1212296Stut { 1312296Stut char line[100]; 1412296Stut int hash = 0, hused = 0; 1512296Stut long totct = 0L; 1612296Stut int ct = 0; 1712296Stut long point; 1812296Stut long opoint = -1; 1912296Stut int m; 2012296Stut int k; 2112296Stut long lp; 2212296Stut long *hpt; 23*17679Sralph int *hfreq; 2412296Stut 25*17679Sralph hpt = (long *) calloc (nhash+1, sizeof(*hpt)); 2612296Stut _assert (hpt != NULL); 27*17679Sralph hfreq = (int *) calloc (nhash, sizeof(*hfreq)); 28*17679Sralph _assert (hfreq != NULL); 2912296Stut hpt[0] = 0; 3012296Stut lp= 0; 3112296Stut while (fgets(line, 100, ft)) 3212296Stut { 3312296Stut totct++; 3412296Stut sscanf(line, "%d %ld", &k, &point); 3512296Stut if (hash < k) 3612296Stut { 3712296Stut hused++; 3812296Stut if (iflong) putl(-1L, fb); 3912296Stut else putw(-1, fb); 4012296Stut hfreq[hash]=ct; 4112296Stut while (hash<k) 4212296Stut { 4312296Stut hpt[++hash] = lp; 4412296Stut hfreq[hash] = 0; 4512296Stut } 4612296Stut hpt[hash] = lp += iflong? sizeof(long) : sizeof(int); 4712296Stut opoint= -1; 4812296Stut ct=0; 4912296Stut } 5012296Stut if (point!=opoint) 5112296Stut { 5212296Stut if (iflong) 5312296Stut putl(opoint=point, fb); 5412296Stut else 5512296Stut putw( (int)(opoint=point), fb); 5612296Stut lp += iflong? sizeof(long) : sizeof(int); 5712296Stut ct++; 5812296Stut } 5912296Stut } 6012296Stut if (iflong) putl(-1L, fb); 6112296Stut else putw(-1,fb); 6212296Stut while (hash<nhash) 6312296Stut hpt[++hash]=lp; 6412296Stut fwrite(&nhash, sizeof(nhash), 1, fa); 6512296Stut fwrite(&iflong, sizeof(iflong), 1, fa); 6612296Stut fwrite(hpt, sizeof(*hpt), nhash, fa); 6712296Stut fwrite (hfreq, sizeof(*hfreq), nhash, fa); 6812296Stut *ptotct = totct; 6912296Stut *phused = hused; 7012296Stut } 7112296Stut 7212296Stut putl(ll, f) 7312296Stut long ll; 7412296Stut FILE *f; 7512296Stut { 7612296Stut putw(ll, f); 7712296Stut } 7812296Stut 7912296Stut long 8012296Stut getl(f) 8112296Stut FILE *f; 8212296Stut { 8312296Stut return(getw(f)); 8412296Stut } 85