Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/refer/inv6.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


# 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;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.