|
|
1.1 root 1: /* @(#)hashlook.c 1.4 */
2: #include <stdio.h>
3: #include "hash.h"
4: #include "huff.h"
5:
6: unsigned *table;
7: unsigned short index[NI];
8:
9: #define B (BYTE*sizeof(unsigned))
10: #define L (BYTE*sizeof(long)-1)
11: #define MASK (~(1L<<L))
12:
13: #ifdef pdp11 /*sizeof(unsigned)==sizeof(long)/2 */
14: #define fetch(wp,bp)\
15: (((((long)wp[0]<<B)|wp[1])<<(B-bp))|(wp[2]>>bp))
16: #else /*sizeof(unsigned)==sizeof(long)*/
17: #define fetch(wp,bp) (bp==B?wp[0]:((wp[0]<<(B-bp))|(wp[1]>>bp)))
18: #endif
19:
20: hashlook(s)
21: char *s;
22: {
23: long h;
24: long t;
25: register bp;
26: register unsigned *wp;
27: int i;
28: long sum;
29: unsigned *tp;
30:
31: h = hash(s);
32: t = h>>(HASHWIDTH-INDEXWIDTH);
33: wp = &table[index[t]];
34: tp = &table[index[t+1]];
35: bp = B;
36: sum = (long)t<<(HASHWIDTH-INDEXWIDTH);
37: for(;;) {
38: {/* this block is equivalent to
39: bp -= decode((fetch(wp,bp)>>1)&MASK, &t);*/
40: long y;
41: long v;
42: y = (fetch(wp,bp)>>1) & MASK;
43: if(y < cs) {
44: t = y >> (L+1-w);
45: bp -= w-1;
46: }
47: else {
48: for(bp-=w,v=v0; y>=qcs; y=(y<<1)&MASK,v+=n)
49: bp -= 1;
50: t = v + (y>>(L-w));
51: }
52: }
53: while(bp<=0) {
54: bp += B;
55: wp++;
56: }
57: if(wp>=tp&&(wp>tp||bp<B))
58: return(0);
59: sum += t;
60: if(sum<h)
61: continue;
62: return(sum==h);
63: }
64: }
65:
66:
67: prime(argc,argv)
68: char **argv;
69: {
70: register FILE *f;
71: register fd;
72: extern char *malloc();
73: if(argc <= 1)
74: return(0);
75: #ifndef pdp11
76: if(sizeof(long) > sizeof(unsigned))
77: abort(); /*wrong fetch macro*/
78: #endif
79: #ifdef pdp11 /* because of insufficient address space for buffers*/
80: fd = dup(0);
81: close(0);
82: if(open(argv[1], 0) != 0)
83: return(0);
84: f = stdin;
85: if(rhuff(f)==0
86: || read(fileno(f), (char *)index, NI*sizeof(*index)) != NI*sizeof(*index)
87: || (table = (unsigned*)malloc(index[NI-1]*sizeof(*table))) == 0
88: || read(fileno(f), (char*)table, sizeof(*table)*index[NI-1])
89: != index[NI-1]*sizeof(*table))
90: return(0);
91: close(0);
92: if(dup(fd) != 0)
93: return(0);
94: close(fd);
95: #else
96: if((f = fopen(argv[1], "ri")) == NULL)
97: return(0);
98: if(rhuff(f)==0
99: || fread((char*)index, sizeof(*index), NI, f) != NI
100: || (table = (unsigned*)malloc(index[NI-1]*sizeof(*table))) == 0
101: || fread((char*)table, sizeof(*table), index[NI-1], f)
102: != index[NI-1])
103: return(0);
104: fclose(f);
105: #endif
106: hashinit();
107: return(1);
108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.