static char *sccsid
= "@(#)hunt2.c 4.5 (Berkeley) 9/28/87";
extern int *hfreq
, hfrflg
, hcomp(), hexch();
doquery(hpt
, nhash
, fb
, nitem
, qitem
, master
)
int nf
= 0, best
= 0, nterm
= 0, i
, g
, j
;
extern int lmaster
, colevel
, reached
;
fprintf(stderr
, "entering doquery nitem %d\n",nitem
);
fprintf(stderr
, "first few hashes are %ld %ld %ld %ld %ld\n", hpt
[0],hpt
[1],hpt
[2],hpt
[3],hpt
[4]);
fprintf(stderr
, "and frequencies are %d %d %d %d %d\n",hfreq
[0],hfreq
[1],hfreq
[2],hfreq
[3],hfreq
[4]);
umaster
.b
= (long *) master
;
coord
= (int *) zalloc(lmaster
, sizeof(lmaster
));
prevdrop
.b
= (long *) zalloc(lmaster
, sizeof(long));
prevdrop
.a
= (unsigned *) zalloc(lmaster
, sizeof(int));
prevcoord
= (int *) zalloc(lmaster
, sizeof(lmaster
));
fprintf(stderr
, "nitem %d\n",nitem
);
hh
[i
] = hash(qitem
[i
])%nhash
;
fprintf(stderr
,"query wd X%sX has hash %d\n", qitem
[i
], hh
[i
]);
fprintf(stderr
, "past that loop nhash %d hpt is %lo\n", nhash
, hpt
);
fprintf(stderr
,"item %s hash %d hfreq %d\n",qitem
[i
], hh
[i
], hfreq
[hh
[i
]]);
/* if possible, sort query into decreasing frequency of hashes */
shell (nitem
, hcomp
, hexch
);
fprintf(stderr
, "item hash %d frq %d\n", hh
[i
], hfreq
[hh
[i
]]);
fprintf(stderr
,"first item hash %d lp %ld 0%lo\n", hh
[0],lp
,lp
);
_assert (fseek(fb
, lp
, 0) != -1);
fprintf(stderr
,"umaster has %ld\n",(umaster
.b
[i
]));
fprintf(stderr
,"umaster has %d\n",(umaster
.a
[i
]));
if (umaster
.b
[i
] == -1L) break;
if (umaster
.a
[i
] == -1) break;
for(nterm
=1; nterm
<nitem
; nterm
++)
fprintf(stderr
, "item %d, hash %d\n", nterm
, hh
[nterm
]);
prevdrop
.b
[j
] = umaster
.b
[j
];
prevdrop
.a
[j
] = umaster
.a
[j
];
_assert (fseek(fb
, lp
, 0) != -1);
fprintf(stderr
,"item %d hash %d seek to %ld\n",nterm
,hh
[nterm
],lp
);
fprintf(stderr
,"next term finds %ld\n",k
);
fprintf(stderr
, "bfwh j %d nf %d master %ld k %ld\n",j
,nf
,prevdrop
.b
[j
],(long)(k
));
fprintf(stderr
, "bfwh j %d nf %d master %ld k %ld\n",j
,nf
,prevdrop
.a
[j
],(long)(k
));
while (j
<nf
&& (iflong
?prevdrop
.b
[j
]:prevdrop
.a
[j
])<k
)
fprintf(stderr
, "j %d nf %d prevdrop %ld prevcoord %d colevel %d nterm %d k %ld\n",
j
,nf
,prevdrop
.b
[j
], prevcoord
[j
], colevel
, nterm
, (long)(k
));
fprintf(stderr
, "j %d nf %d prevdrop %ld prevcoord %d colevel %d nterm %d k %ld\n",
j
,nf
,prevdrop
.a
[j
], prevcoord
[j
], colevel
, nterm
, (long)(k
));
if (prevcoord
[j
] + colevel
<= nterm
)
umaster
.b
[g
] = prevdrop
.b
[j
];
umaster
.a
[g
] = prevdrop
.a
[j
];
coord
[g
++] = prevcoord
[j
++];
fprintf(stderr
, " not skip g %d doc %d coord %d note %d\n",g
,umaster
.b
[g
-1], coord
[g
-1],umaster
.b
[j
-1]);
fprintf(stderr
, " not skip g %d doc %ld coord %d nterm %d\n",g
,umaster
.a
[g
-1], coord
[g
-1],nterm
);
if (colevel
==0 && j
>=nf
) break;
if (j
<nf
&& (iflong
? prevdrop
.b
[j
]: prevdrop
.a
[j
]) == k
)
coord
[g
++] = prevcoord
[j
++]+1;
fprintf(stderr
, " at g %d item %ld coord %d note %ld\n",g
,umaster
.b
[g
-1],coord
[g
-1],umaster
.b
[j
-1]);
fprintf(stderr
, " at g %d item %d coord %d note %d\n",g
,umaster
.a
[g
-1],coord
[g
-1],umaster
.a
[j
-1]);
fprintf(stderr
,"now have %d items\n",g
);
if (prevcoord
[j
]+colevel
> nterm
)
umaster
.b
[g
] = prevdrop
.b
[j
];
umaster
.a
[g
] = prevdrop
.a
[j
];
coord
[g
++] = prevcoord
[j
];
fprintf(stderr
, "copied over %ld coord %d\n",umaster
.b
[g
-1], coord
[g
-1]);
fprintf(stderr
, "copied over %d coord %d\n",umaster
.a
[g
-1], coord
[g
-1]);
if (coord
[j
]>best
) best
= coord
[j
];
fprintf(stderr
, "colevel %d best %d\n", colevel
, best
);
umaster
.b
[g
++] = umaster
.b
[j
];
umaster
.a
[g
++] = umaster
.a
[j
];
fprintf(stderr
, "yet got %d\n",nf
);
fprintf(stderr
, " returning with %d\n",nf
);
free(prevdrop
, lmaster
, iflong
?sizeof(long): sizeof(int));
free(prevcoord
, lmaster
, sizeof (lmaster
));
fprintf(stderr
,":%ld\n",umaster
.b
[g
]);
fprintf(stderr
,":%d\n",umaster
.a
[g
]);
return (hfreq
[hh
[n1
]]<=hfreq
[hh
[n2
]]);