|
|
1.1 ! root 1: # include "stdio.h" ! 2: # include "assert.h" ! 3: whash(ft, fa, fb, nhash, iflong, ptotct, phused) ! 4: FILE *fa, *fb, *ft; ! 5: int nhash, *phused; ! 6: long *ptotct; ! 7: { ! 8: char line[100]; ! 9: int hash = 0, hused = 0; ! 10: long totct = 0L; ! 11: int ct = 0; ! 12: long point; ! 13: long opoint = -1; ! 14: int m; ! 15: int k; long lp; ! 16: long *hpt; ! 17: int *hfreq = NULL; ! 18: ! 19: hpt = calloc (nhash+1, sizeof(*hpt)); ! 20: _assert (hpt != NULL); ! 21: hfreq = calloc (nhash, sizeof(*hfreq)); ! 22: _assert (hfreq !=NULL); ! 23: hpt[0] = 0; ! 24: lp= 0; ! 25: while (fgets(line, 100, ft)) ! 26: { ! 27: totct++; ! 28: sscanf(line, "%d %ld", &k, &point); ! 29: if (hash < k) ! 30: { ! 31: hused++; ! 32: if (iflong) putl(-1L, fb); else putw(-1, fb); ! 33: hfreq[hash]=ct; ! 34: while (hash<k) ! 35: { ! 36: hpt[++hash] = lp; ! 37: hfreq[hash] = 0; ! 38: } ! 39: hpt[hash] = lp += iflong? sizeof(long) : sizeof(int); ! 40: opoint= -1; ! 41: ct=0; ! 42: } ! 43: if (point!=opoint) ! 44: { ! 45: if (iflong) ! 46: putl(opoint=point, fb); ! 47: else ! 48: putw( (int)(opoint=point), fb); ! 49: lp += iflong? sizeof(long) : sizeof(int); ! 50: ct++; ! 51: } ! 52: } ! 53: if (iflong) putl(-1L, fb); else putw(-1,fb); ! 54: while (hash<nhash) ! 55: hpt[++hash]=lp; ! 56: fwrite(&nhash, sizeof(nhash), 1, fa); ! 57: fwrite(&iflong, sizeof(iflong), 1, fa); ! 58: fwrite(hpt, sizeof(*hpt), nhash, fa); ! 59: fwrite (hfreq, sizeof(*hfreq), nhash, fa); ! 60: *ptotct = totct; ! 61: *phused = hused; ! 62: } ! 63: putl(ll, f) ! 64: long ll; ! 65: FILE *f; ! 66: { ! 67: putw(ll, f); ! 68: } ! 69: long getl(f) ! 70: FILE *f; ! 71: { ! 72: return(getw(f)); ! 73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.