# include "inv.h" # include "assert.h" void whash(FILE *ft, FILE *fa, FILE *fb, int nhash, long *ptotct, int *phused) { char line[100]; int hash = 0, hused = 0; long totct = 0L; int ct = 0; long point; long opoint = -1; int k; long lp; long *hpt, *hfreq; Index ind; initindex(&ind); growindex(&ind, nhash+1); /* +1 since nhash might be zero */ ind.n = nhash; hpt = ind.hash.el; hfreq = ind.freq.el; hpt[0] = 0; lp = 0; while (fgets(line, sizeof(line), ft)) { totct++; if (sscanf(line, "%d %ld", &k, &point) != 2) err("bad input file to whash"); if (hash < k) { hused++; putl(-1L, fb); hfreq[hash] = ct; if (k >= nhash) err("corrupt index file -- rerun pubindex?"); while (hash < k) { hpt[++hash] = lp; hfreq[hash] = 0; } hpt[hash] = lp += sizeof(long); opoint = -1; ct = 0; } if (point != opoint) { putl(opoint = point, fb); lp += sizeof(long); ct++; } } putl(-1L, fb); while (++hash < nhash) hpt[hash] = lp; putindex(&ind, fa); emptyindex(&ind); *ptotct = totct; *phused = hused; }