00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 #include <memory.h>
00092 #include "udanax.h"
00093
00101 bool
00102 insertspanf(
00103 Session *sess,
00104 typespanf spanfptr,
00105 IStreamAddr *isaptr,
00106 typesporglset sporglset,
00107 int spantype)
00108 {
00109 typedsp crumorigin;
00110 typewid crumwidth;
00111 Tumbler lstream, lwidth;
00112 type2dbottomcruminfo linfo;
00113
00114 prefixtumbler(isaptr, spantype, &crumorigin.dsas[ORGLRANGE]);
00115 tumblerclear(&crumwidth.dsas[ORGLRANGE]);
00116 clear(&linfo, sizeof(linfo));
00117 for (; sporglset; sporglset = (typesporglset) ((typeitemheader *) sporglset)->next) {
00118 if (((typeitemheader *) sporglset)->itemid == ISPANID) {
00119 movetumbler(&((typeispan *) sporglset)->stream, &lstream);
00120 movetumbler(&((typeispan *) sporglset)->width, &lwidth);
00121 movetumbler(isaptr, &linfo.homedoc);
00122 } else if (((typeitemheader *) sporglset)->itemid == SPORGLID) {
00123 movetumbler(&((typesporgl *) sporglset)->sporglorigin, &lstream);
00124 movetumbler(&((typesporgl *) sporglset)->sporglwidth, &lwidth);
00125 movetumbler(&((typesporgl *) sporglset)->sporgladdress, &linfo.homedoc);
00126 } else if (((typeitemheader *) sporglset)->itemid == TEXTID) {
00127 movetumbler(isaptr, &lstream);
00128
00129
00130 tumblerclear(&lwidth);
00131 lwidth.mantissa[1] = ((typetext *) sporglset)->length;
00132 tumblerjustify(&lwidth);
00133
00134 movetumbler(isaptr, &linfo.homedoc);
00135 } else
00136 assert(0);
00137
00138 movetumbler(&lstream, &crumorigin.dsas[SPANRANGE]);
00139 movetumbler(&lwidth, &crumwidth.dsas[SPANRANGE]);
00140 insertnd(sess, (typecuc *) spanfptr, &crumorigin, &crumwidth, &linfo, SPANRANGE);
00141 }
00142 return true;
00143 }
00144
00152 bool
00153 findlinksfromtothreesp(
00154 Session *sess,
00155 typespanf spanfptr,
00156 typespecset fromvspecset,
00157 typespecset tovspecset,
00158 typespecset threevspecset,
00159 typeispan *orglrange,
00160 typelinkset *linksetptr)
00161 {
00162 typesporglset fromsporglset;
00163 typesporglset tosporglset;
00164 typesporglset threesporglset;
00165 typelinkset fromlinkset;
00166 typelinkset tolinkset;
00167 typelinkset threelinkset;
00168 bool olddebug = debug;
00169
00170 #ifndef DISTRIBUTION
00171 if (debug) {
00172 L("findlinksfromtothreesp fromset = %x, toset = %x, threeset = %x\n", (int) fromvspecset, (int) tovspecset,
00173 (int) threevspecset);
00174 }
00175 #endif
00176
00177 fromlinkset = tolinkset = threelinkset = NULL;
00178
00179 if (fromvspecset)
00180 specset2sporglset(sess, fromvspecset, &fromsporglset, NOBERTREQUIRED);
00181
00182 if (tovspecset)
00183 specset2sporglset(sess, tovspecset, &tosporglset, NOBERTREQUIRED);
00184
00185 if (threevspecset)
00186 specset2sporglset(sess, threevspecset, &threesporglset, NOBERTREQUIRED);
00187
00188 if (fromvspecset) {
00189 sporglset2linkset(sess, (typecuc *) spanfptr, fromsporglset, &fromlinkset, orglrange, LINKFROMSPAN);
00190 if (!fromlinkset) {
00191 *linksetptr = NULL;
00192 debug = olddebug;
00193 return true;
00194 }
00195 }
00196
00197 if (tovspecset) {
00198 sporglset2linkset(sess, (typecuc *) spanfptr, tosporglset, &tolinkset, orglrange, LINKTOSPAN);
00199 if (!tolinkset) {
00200 *linksetptr = NULL;
00201 debug = olddebug;
00202 return true;
00203 }
00204 }
00205
00206 if (threevspecset) {
00207 sporglset2linkset(sess, (typecuc *) spanfptr, threesporglset, &threelinkset, orglrange, LINKTHREESPAN);
00208 if (!threelinkset) {
00209 *linksetptr = NULL;
00210 debug = olddebug;
00211 return true;
00212 }
00213 }
00214
00215 intersectlinksets(sess, fromlinkset, tolinkset, threelinkset, linksetptr);
00216 debug = olddebug;
00217 return true;
00218 }
00219
00227 bool
00228 findnumoflinksfromtothreesp(
00229 Session *sess,
00230 typespanf spanfptr,
00231 typespecset fromvspecset,
00232 typespecset tovspecset,
00233 typespecset threevspecset,
00234 typeispan *orglrange,
00235 int *numptr)
00236 {
00237 typelinkset linkset;
00238 int n;
00239
00240 if (!findlinksfromtothreesp(sess, spanfptr, fromvspecset, tovspecset, threevspecset, orglrange, &linkset))
00241 return (false);
00242
00243 for (n = 0; linkset; linkset = linkset->next, ++n)
00244 ;
00245
00246 *numptr = n;
00247 return true;
00248 }
00249
00257 bool
00258 findnextnlinksfromtothreesp(
00259 Session *sess,
00260 typespecset fromvspecset,
00261 typespecset tovspecset,
00262 typespecset threevspecset,
00263 typeispan *orglrangeptr,
00264 IStreamAddr *lastlinkisaptr,
00265 typelinkset *nextlinksetptr,
00266 int *nptr)
00267 {
00268 int n;
00269 typelinkset linkset;
00270
00271 n = 0;
00272 *nextlinksetptr = NULL;
00273
00274 if (!findlinksfromtothreesp(sess, spanf, fromvspecset, tovspecset, threevspecset, orglrangeptr, &linkset))
00275 return false;
00276
00277 if (iszerotumbler(lastlinkisaptr)) {
00278 *nextlinksetptr = linkset;
00279 } else {
00280 for (; linkset; linkset = linkset->next) {
00281 if (tumblereq(&linkset->address, lastlinkisaptr)) {
00282 *nextlinksetptr = linkset->next;
00283 break;
00284 }
00285 }
00286 }
00287
00288 if (!linkset) {
00289 *nextlinksetptr = NULL;
00290 *nptr = 0;
00291 return true;
00292 }
00293
00294 for (linkset = *nextlinksetptr; linkset; linkset = linkset->next) {
00295 if (++n >= *nptr) {
00296 linkset->next = NULL;
00297 break;
00298 }
00299 }
00300 *nptr = n;
00301 return true;
00302 }
00303
00311 bool
00312 finddocscontainingsp(
00313 Session *sess,
00314 typespanset ispanset,
00315 typelinkset *addresssetptr)
00316 {
00317 Tumbler docid;
00318 Context *context, *c;
00319 typelinkset *headptr;
00320 typelink document;
00321 typespan docspace;
00322
00323 #ifndef DISTRIBUTION
00324 if (debug) {
00325 L("\nFINDDOCSCONTAININGsp\n");
00326 fooitemset("", (typeitem *) ispanset);
00327 }
00328 #endif
00329
00330 headptr = addresssetptr;
00331 *addresssetptr = NULL;
00332 clear(&docspace, sizeof(typespan));
00333 tumblerincrement(&docspace.stream, 0, DOCISPAN, &docspace.stream);
00334 tumblerincrement(&docspace.width, 0, 1, &docspace.width);
00335
00336 for (; ispanset; ispanset = ispanset->next) {
00337 context = retrieverestricted((typecuc *) spanf, &docspace, ORGLRANGE, ispanset, SPANRANGE, (IStreamAddr *) NULL);
00338
00339 for (c = context; c; c = (Context *) c->nextcontext) {
00340 movetumbler(&c->totaloffset.dsas[ORGLRANGE], &docid);
00341 beheadtumbler(&docid, &document.address);
00342 if (isinlinklist(*headptr, &document.address))
00343 continue;
00344
00345 document.itemid = LINKID;
00346 document.next = NULL;
00347 addresssetptr = (typelinkset *) onitemlist(sess, (typeitem *) & document, (typeitemset *) addresssetptr);
00348 }
00349 contextfree(context);
00350 }
00351
00352 #ifndef DISTRIBUTION
00353 if (debug)
00354 fooitemset("", (typeitem *) *headptr);
00355 #endif
00356
00357 return true;
00358 }
00359
00367 static bool
00368 retrievesporglsetinrange(
00369 Session *sess,
00370 typesporglset sporglptr,
00371 typespan *whichspace,
00372 typesporglset *sporglsetptr)
00373 {
00374 Context *context, *c, *tmp;
00375 typesporgl *sporglset;
00376
00377 for (; sporglptr; sporglptr = (typesporglset) sporglptr->xxxxsporgl.next) {
00378 context = retrieverestricted((typecuc *) spanf, (typespan *) sporglptr, SPANRANGE, whichspace, ORGLRANGE, (IStreamAddr *) NULL
00379 );
00380
00381
00382 for (c = context; c;) {
00383 sporglset = new(sess) typesporgl;
00384 contextintosporgl((type2dcontext *) c, (Tumbler *) NULL, sporglset, SPANRANGE);
00385 *sporglsetptr = (typesporglset) sporglset;
00386 sporglsetptr = (typesporglset *) & sporglset->next;
00387
00388 tmp = (Context *) c->nextcontext;
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 c = tmp;
00399 }
00400 contextfree(context);
00401 }
00402 return true;
00403 }
00404
00412 bool
00413 retrieveendsetsfromspanf(
00414 Session *sess,
00415 typespecset specset,
00416 typespecset *fromsetptr,
00417 typespecset *tosetptr,
00418 typespecset *threesetptr)
00419 {
00420 typespan fromspace, tospace, threespace;
00421 typesporglset sporglset;
00422 typesporglset fromsporglset;
00423 typesporglset tosporglset;
00424 typesporglset threesporglset;
00425 bool bang(), retrievesporglsetinrange(), linksporglset2specset();
00426 bool temp;
00427
00428 #ifndef DISTRIBUTION
00429 if (debug) {
00430 L("retrieveendsetsfromspanf\n");
00431 fooitemset("", (typeitem *) specset);
00432 }
00433 #endif
00434
00435 clear(&fromspace, sizeof(typespan));
00436 clear(&tospace, sizeof(typespan));
00437 clear(&threespace, sizeof(typespan));
00438
00439 fromspace.stream.mantissa[0] = LINKFROMSPAN;
00440 fromspace.width.mantissa[0] = 1;
00441
00442 tospace.stream.mantissa[0] = LINKTOSPAN;
00443 tospace.width.mantissa[0] = 1;
00444
00445 threespace.stream.mantissa[0] = LINKTHREESPAN;
00446 threespace.width.mantissa[0] = 1;
00447
00448 fromsporglset = tosporglset = threesporglset = NULL;
00449
00450 if (!(specset2sporglset(sess, specset, &sporglset, NOBERTREQUIRED)
00451 && retrievesporglsetinrange(sess, sporglset, &fromspace, &fromsporglset)
00452 && linksporglset2specset(sess, &((typevspec *) specset)->docisa, fromsporglset, fromsetptr, NOBERTREQUIRED)
00453 && retrievesporglsetinrange(sess, sporglset, &tospace, &tosporglset)
00454 && linksporglset2specset(sess, &((typevspec *) specset)->docisa, tosporglset, tosetptr, NOBERTREQUIRED))) {
00455 return false;
00456 }
00457 if (threesetptr) {
00458 temp = (retrievesporglsetinrange(sess, sporglset, &threespace, &threesporglset)
00459 && linksporglset2specset(sess, &((typevspec *) specset)->docisa, threesporglset, threesetptr,
00460 NOBERTREQUIRED));
00461 return temp;
00462 }
00463 return true;
00464 }