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