1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2 /* All Rights Reserved */ 3 4 5 /* 6 * Copyright (c) 1980 Regents of the University of California. 7 * All rights reserved. The Berkeley software License Agreement 8 * specifies the terms and conditions for redistribution. 9 */ 10 11 /* 12 * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. 13 * All Rights Reserved. 14 */ 15 16 #pragma ident "%Z%%M% %I% %E% SMI" 17 18 #include <stdio.h> 19 #include <assert.h> 20 21 whash(ft, fa, fb, nhash, iflong, ptotct, phused) 22 FILE *fa, *fb, *ft; 23 int nhash, *phused; 24 long *ptotct; 25 { 26 char line[100]; 27 int hash = 0, hused = 0; 28 long totct = 0L; 29 int ct = 0; 30 long point; 31 long opoint = -1; 32 int m; 33 int k; 34 long lp; 35 long *hpt; 36 int *hfreq = NULL; 37 38 hpt = (long *) calloc (nhash+1, sizeof(*hpt)); 39 assert (hpt != NULL); 40 hfreq = (int *) calloc (nhash, sizeof(*hfreq)); 41 assert (hfreq != NULL); 42 hpt[0] = 0; 43 lp= 0; 44 while (fgets(line, 100, ft)) 45 { 46 totct++; 47 sscanf(line, "%d %ld", &k, &point); 48 if (hash < k) 49 { 50 hused++; 51 if (iflong) putl(-1L, fb); 52 else putw(-1, fb); 53 hfreq[hash]=ct; 54 while (hash<k) 55 { 56 hpt[++hash] = lp; 57 hfreq[hash] = 0; 58 } 59 hpt[hash] = lp += iflong? sizeof(long) : sizeof(int); 60 opoint= -1; 61 ct=0; 62 } 63 if (point!=opoint) 64 { 65 if (iflong) 66 putl(opoint=point, fb); 67 else 68 putw( (int)(opoint=point), fb); 69 lp += iflong? sizeof(long) : sizeof(int); 70 ct++; 71 } 72 } 73 if (iflong) putl(-1L, fb); 74 else putw(-1,fb); 75 while (hash<nhash) 76 hpt[++hash]=lp; 77 fwrite(&nhash, sizeof(nhash), 1, fa); 78 fwrite(&iflong, sizeof(iflong), 1, fa); 79 fwrite(hpt, sizeof(*hpt), nhash, fa); 80 fwrite (hfreq, sizeof(*hfreq), nhash, fa); 81 *ptotct = totct; 82 *phused = hused; 83 } 84 85 putl(ll, f) 86 long ll; 87 FILE *f; 88 { 89 putw(ll, f); 90 } 91 92 long 93 getl(f) 94 FILE *f; 95 { 96 return(getw(f)); 97 } 98