libsrc/correspond.cxx

Go to the documentation of this file.
00001 /**********************************************************************
00002  * Copyright 2002 Jeff Rush <jrush@taupro.com>
00003  * Original Copyright 1979-2002 Udanax.com
00004  *
00005  * This file is part of the Udanax xanalogical storage system.
00006  *
00007  * Udanax is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Udanax is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with Udanax; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  **********************************************************************/
00021 
00030 /* Modification History:
00031  * $Log: correspond.cxx,v $
00032  * Revision 1.13  2004/09/04 16:02:17  jrush
00033  * Added Doxygen headers before each and every function definition.
00034  *
00035  * Revision 1.12  2002/07/26 04:30:29  jrush
00036  * Replaced gerror() with assert()
00037  *
00038  * Revision 1.11  2002/05/28 04:22:29  jrush
00039  * Adjusted source files to comply with GPL licensing.
00040  *
00041  * Revision 1.10  2002/05/28 02:49:42  jrush
00042  * Made static any functions and global variables private to this source file
00043  * and commented out any unused functions.
00044  *
00045  * Revision 1.9  2002/04/16 22:39:50  jrush
00046  * Converted many #defines into enumeration types instead, and adjusted
00047  * function prototypes accordingly.
00048  *
00049  * Revision 1.8  2002/04/12 11:56:42  jrush
00050  * Reorganized include file layout, renamed xanadu.h to udanax.h and
00051  * typecontext/typecrumcontext to C++ class Context/CrumContext.
00052  *
00053  * Revision 1.7  2002/04/09 21:45:46  jrush
00054  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00055  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00056  * up the type/class tree.
00057  *
00058  * Revision 1.6  2002/04/06 20:42:50  jrush
00059  * Switch from sess->alloc() style to new(sess) Object parameterized allocator.
00060  *
00061  * Revision 1.5  2002/04/06 19:51:30  jrush
00062  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00063  *
00064  * Revision 1.4  2002/04/06 17:05:57  jrush
00065  * Switched from referring to 'task' for a client connection to 'session',
00066  * and converted the typetask typedef/struct into a Session C++ class.
00067  *
00068  * Revision 1.3  2002/04/06 15:01:17  jrush
00069  * Changed INT to just 'int'.
00070  *
00071  * Revision 1.2  2002/02/14 09:27:43  jrush
00072  * Cleaned up source:
00073  *
00074  * 1. ran thru the indent tool to achieve a standard look,
00075  * 2. added structured comments at top for use with DOxygen reporting
00076  *    as well as CVS keywords,
00077  * 3. fixed compiler warnings re ambiguous assign/compares,
00078  *    needed casts and unused/uninitialized variables,
00079  * 4. fixed funcs that didn't specify a return type,
00080  * 5. centralized prototypes in protos.h, removing incomplete ones,
00081  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00082  * 7. fixed initializer nesting in tumbler constants,
00083  * 8. renamed vars that conflict with C++ keywords (new, this),
00084  * 9. fixed global/extern confusion re some global vars.
00085  *
00086  */
00087 
00088 #include "udanax.h"
00089 
00097     static void
00098 restrictvspecsetovercommonispans(
00099     Session      *sess,          
00100     typeispanset  ispanset,
00101     typespecset   specset,
00102     typespecset  *newspecsetptr)
00103 {
00104     typeorgl versionorgl;
00105     typevspec *s1;
00106     typevspanset docvspanset;
00107 
00108 #ifndef DISTRIBUTION
00109     fooitemset("entering restrictspecsetovercommonispans \n", (typeitem *) ispanset);
00110     fooitemset("\nspecset = \n", (typeitem *) specset);
00111 #endif
00112 
00113     *newspecsetptr = NULL;
00114     for (; ispanset; ispanset = ispanset->next) {
00115         for (; specset; specset = (typespecset) ((typeitemheader *) specset)->next) {
00116             if (!findorgl(sess, granf, &((typevspec *) specset)->docisa, &versionorgl, READBERT))
00117                 assert(0); // restrictvspecset
00118 
00119             docvspanset = NULL;
00120             if (ispan2vspanset(sess, versionorgl, ispanset, &docvspanset)) {
00121                 s1 = new(sess) typevspec;
00122 //                s1 = (typevspec *) sess->alloc(sizeof(typevspec));
00123                 s1->itemid = VSPECID;
00124                 *newspecsetptr = (typespecset) s1;
00125                 movetumbler(&((typevspec *) specset)->docisa, &s1->docisa);
00126                 s1->vspanset = docvspanset;
00127                 newspecsetptr = (typespecset *) & s1->next;
00128             }
00129         }
00130     }
00131     *newspecsetptr = NULL;
00132 #ifndef DISTRIBUTION
00133     fooitemset("leaving restrictspecsetovercommonispans \n", (typeitem *) ispanset);
00134     fooitemset("\nspecset = \n", (typeitem *) specset);
00135     fooitemset("\n newspecset = \n", (typeitem *) *newspecsetptr);
00136 #endif
00137 }
00138 
00146     static void
00147 removespansnotinoriginal(
00148     Session     *sess,          
00149     typespecset  original,
00150     typespecset *newptr)
00151 {
00152     typevspanset newspanset;
00153     typevspec *okspec;
00154 
00155     if (!newptr || !*newptr || !original)
00156         assert(0); // Bad removespans call
00157 
00158     typevspec *first = NULL;
00159     typevspec **nextptr = NULL;
00160 
00161     typespecset newss;
00162     for (newss = *newptr; newss; newss = (typespecset) ((typeitemheader *) newss)->next) {
00163         typespecset oldss;
00164 
00165         for (oldss = original; oldss; oldss = (typespecset) ((typeitemheader *) oldss)->next) {
00166 
00167             if (tumblercmp(&((typevspec *) newss)->docisa, &((typevspec *) oldss)->docisa))
00168                 continue;
00169 
00170             if (intersectspansets(sess, ((typevspec *) newss)->vspanset, ((typevspec *) oldss)->vspanset, &newspanset, VSPANID)) {
00171                 okspec = new(sess) typevspec;
00172 //                okspec = (typevspec *) sess->alloc(sizeof(typevspec));
00173                 okspec->itemid = VSPECID;
00174                 movetumbler(&((typevspec *) newss)->docisa, &okspec->docisa);
00175                 okspec->vspanset = newspanset;
00176 
00177                 if (!first)
00178                     first = okspec;
00179                 else
00180                     *nextptr = okspec;
00181 
00182                 nextptr = &okspec->next;
00183             }
00184         }
00185     }
00186 
00187     sess->freeitemset((typeitemset) * newptr);
00188     *nextptr = NULL;
00189     *newptr = (typespecset) first;
00190 }
00191 
00199     void
00200 restrictspecsetsaccordingtoispans(
00201     Session      *sess,          
00202     typeispanset  ispanset,
00203     typespecset  *specset1,
00204     typespecset  *specset2)
00205 {
00206     typespecset s1;
00207     typespecset s2;
00208 
00209 #ifndef DISTRIBUTION
00210     fooitemset("entering retrievespecsetsaccordingtoispans \n", (typeitem *) *specset1);
00211     fooitemset("\n specset2 = \n", (typeitem *) *specset2);
00212 #endif
00213     restrictvspecsetovercommonispans(sess, ispanset, *specset1, &s1);
00214 /* removespansnotinoriginal (sess, *specset1, &s1); */
00215     removespansnotinoriginal(sess, s1, specset1);
00216 
00217     sess->freeitemset( (typeitemset) s1);
00218 /* *specset1 = s1; */
00219     restrictvspecsetovercommonispans(sess, ispanset, *specset2, &s2);
00220 /* removespansnotinoriginal (sess, *specset2, &s2); */
00221     removespansnotinoriginal(sess, s2, specset2);
00222 
00223     sess->freeitemset( (typeitemset) s2);
00224 /* *specset2 = s2; */
00225 #ifndef DISTRIBUTION
00226     fooitemset("leaving retrievespecsetsaccordingtoispans \n", (typeitem *) *specset1);
00227     fooitemset("\n specset2 = \n", (typeitem *) *specset2);
00228 #endif
00229 }
00230 
00238     static bool
00239 spanintersection(
00240     typespan *aptr,
00241     typespan *bptr,
00242     typespan *cptr)
00243 {
00244     Tumbler aend, bend;
00245 
00246     tumblerclear(&cptr->stream);
00247     tumblerclear(&cptr->width);
00248     tumbleradd(&bptr->stream, &bptr->width, &bend);
00249     if (tumblercmp(&aptr->stream, &bend) >= EQUAL)
00250         return (false);
00251     tumbleradd(&aptr->stream, &aptr->width, &aend);
00252     if (tumblercmp(&bptr->stream, &aend) >= EQUAL)
00253         return (false);
00254 /* these following assignments are clearly wrong 12/4/84 */
00255     switch (tumblercmp(&aptr->stream, &bptr->stream)) {
00256     case EQUAL:                       /* this ones probably ok */
00257         movetumbler(&aptr->stream, &cptr->stream);
00258         switch (tumblercmp(&aend, &bend)) {
00259         case EQUAL:
00260         case LESS:
00261             movetumbler(&aptr->width, &cptr->width);
00262             break;
00263         case GREATER:
00264             movetumbler(&bptr->width, &cptr->width);
00265         }
00266         break;
00267     case GREATER:
00268         movetumbler(&aptr->stream, &cptr->stream);
00269         switch (tumblercmp(&aend, &bend)) {
00270         case EQUAL:
00271         case LESS:                    /* ok */
00272             movetumbler(&aptr->width, &cptr->width);
00273             break;
00274         case GREATER:                 /* ???? */
00275             tumblersub(&bend, &aptr->stream, &cptr->width);
00276 /* movetumbler (&bptr->width, &cptr->width); */
00277         }
00278         break;
00279     case LESS:
00280         movetumbler(&bptr->stream, &cptr->stream);
00281         switch (tumblercmp(&aend, &bend)) {
00282         case EQUAL:
00283         case GREATER:                 /* ok */
00284             movetumbler(&bptr->width, &cptr->width);
00285             break;
00286         case LESS:                    /* ??? */
00287             tumblersub(&aend, &bptr->stream, &cptr->width);
00288 /* movetumbler (&aptr->width, &cptr->width); */
00289         }
00290     }
00291 #ifndef DISTRIBUTION
00292     foospan("in spanintersection \n aspan = ", aptr);
00293     foospan("\n bspan = ", bptr);
00294     foospan("\n cspan = ", cptr);
00295 #endif
00296     return (true);
00297 }
00298 
00306     static bool
00307 comparespans(
00308     Session     *sess,          
00309     typespan    *span1,
00310     typespan    *span2,
00311     typespan   **span3,
00312     typeitemid   spantype)
00313 {
00314     if (iszerotumbler(&span1->width) || iszerotumbler(&span2->width))
00315         return false;
00316 
00317     *span3 = new(sess) typespan;
00318 //    *span3 = (typespan *) sess->alloc(sizeof(typespan));
00319     (*span3)->itemid = spantype;
00320     (*span3)->next   = NULL;
00321 
00322     if (spanintersection(span1, span2, *span3))
00323         return true;
00324     else {
00325         sess->freeexplicit((char *) *span3);
00326         *span3 = NULL;
00327         return false;
00328     }
00329 }
00330 
00338     bool
00339 intersectspansets(
00340     Session     *sess,          
00341     typespanset  set1,
00342     typespanset  set2,
00343     typespanset *set3,
00344     typeitemid   spantype)
00345 {
00346     /*BUG: there is some inconsistency in this function as to whether set3 is a typespanset or a ptr to a typespanset */
00347     typespan *p;
00348 
00349 #ifndef DISTRIBUTION
00350     foo("entering intersectspansets");
00351 #endif
00352 
00353     if (!set1 || !set2 || !set3)
00354         assert(0); // Bad intersectspansets call
00355 
00356 #ifndef DISTRIBUTION
00357     foo("dumping set1\n");
00358     foospanset("", set1);
00359     foo("dumping set2\n");
00360     foospanset("", set2);
00361 #endif
00362     *set3 = NULL;
00363     for (; set1; set1 = set1->next) {
00364         for (p = set2; p; p = p->next) {
00365             if (comparespans(sess, set1, p, set3, spantype))
00366                 set3 = &(*set3)->next;
00367         }
00368     }
00369 #ifndef DISTRIBUTION
00370     foo("leaving intersectspansets");
00371     foo("dumping set3\n");
00372     foospanset("", *set3);
00373 #endif
00374     return true;
00375 }
00376 
00384     static typespanpair *
00385 makespanpair(
00386     Session *sess,          
00387     Tumbler *doc1,
00388     Tumbler *start1,
00389     Tumbler *doc2,
00390     Tumbler *start2,
00391     Tumbler *width)
00392 {
00393     typespanpair *spanpair = new(sess) typespanpair;
00394     //    spanpair = (typespanpair *) sess->alloc(sizeof(typespanpair));
00395 
00396     docidandvstream2tumbler(doc1, start1, &spanpair->stream1);
00397     docidandvstream2tumbler(doc2, start2, &spanpair->stream2);
00398     movetumbler(width, &spanpair->widthofspan);
00399 
00400     return spanpair;
00401 }
00402 
00410 static void
00411 makespanpairsforispan(
00412     Session         *sess,          
00413     Tumbler         *iwidth,
00414     typespecset     *specset1ptr,
00415     typespecset     *specset2ptr,
00416     typespanpairset *pairsetptr)
00417 {
00418     typevspec *spec1, *spec2;
00419     typespan *span1, *span2;
00420     Tumbler sum;
00421     int cmp;
00422 
00423 #ifndef DISTRIBUTION
00424     foo("entering makespanpairsforispan\n");
00425     fooitemset("\n*specset1ptr = \n", (typeitem *) *specset1ptr);
00426     fooitemset("\n*specset2ptr = \n", (typeitem *) *specset2ptr);
00427 #endif
00428     *pairsetptr = NULL;
00429     tumblerclear(&sum);
00430     spec1 = (typevspec *) * specset1ptr;
00431     span1 = spec1->vspanset;
00432     spec2 = (typevspec *) * specset2ptr;
00433     span2 = spec2->vspanset;
00434     while (span1 && span2 && tumblercmp(iwidth, &sum) == GREATER) {
00435         cmp = tumblercmp(&span1->width, &span2->width);
00436         switch (cmp) {
00437         case LESS:
00438         case EQUAL:
00439             *pairsetptr =
00440                     makespanpair(sess, &spec1->docisa, &span1->stream, &spec2->docisa, &span2->stream,
00441                                  &span1->width);
00442             tumbleradd(&sum, &span1->width, &sum);
00443             if (cmp == EQUAL)
00444                 span2 = span2->next;
00445             else {
00446                 tumbleradd(&span2->stream, &span1->width, &span2->stream);
00447                 tumblersub(&span2->width, &span1->width, &span2->width);
00448             }
00449             span1 = span1->next;
00450             break;
00451         case GREATER:
00452             *pairsetptr =
00453                     makespanpair(sess, &spec1->docisa, &span1->stream, &spec2->docisa, &span2->stream,
00454                                  &span2->width);
00455             tumbleradd(&sum, &span2->width, &sum);
00456             tumbleradd(&span1->stream, &span2->width, &span1->stream);
00457             tumblersub(&span1->width, &span2->width, &span1->width);
00458             span2 = span2->next;
00459         }
00460         spec1->vspanset = span1;
00461         spec2->vspanset = span2;
00462         if (!span1) {
00463             spec1 = spec1->next;
00464             *specset1ptr = (typespecset) spec1;
00465             if (spec1)
00466                 span1 = spec1->vspanset;
00467         }
00468         if (!span2) {
00469             spec2 = spec2->next;
00470             *specset2ptr = (typespecset) spec2;
00471             if (spec2)
00472                 span2 = spec2->vspanset;
00473         }
00474         pairsetptr = &(*pairsetptr)->nextspanpair;
00475     }
00476 #ifndef DISTRIBUTION
00477     foo("leaving makespanpairsforispan\n");
00478 #endif
00479 }
00480 
00488     void
00489 makespanpairset(
00490     Session         *sess,          
00491     typeispanset     ispanset,
00492     typespecset      specset1,
00493     typespecset      specset2,
00494     typespanpairset *pairsetptr)
00495 {
00496     Tumbler iwidth;
00497     typespanpairset pairset;
00498 
00499 #ifndef DISTRIBUTION
00500     foo("entering makespanpairset");
00501     fooitemset("ispanset = \n", (typeitem *) ispanset);
00502     fooitemset("specset1 = \n", (typeitem *) specset1);
00503     fooitemset("specset2 = \n", (typeitem *) specset2);
00504 #endif
00505     *pairsetptr = NULL;
00506     for (; ispanset; ispanset = ispanset->next) {
00507         movetumbler(&ispanset->width, &iwidth);
00508         makespanpairsforispan(sess, &iwidth, &specset1, &specset2, &pairset);
00509         *pairsetptr = pairset;
00510         pairsetptr = &pairset->nextspanpair;
00511     }
00512     *pairsetptr = NULL;
00513 #ifndef DISTRIBUTION
00514     foo("leaving makespanpairset");
00515 #endif
00516 }
00517 
00518 //UNUSED
00519 //UNUSED static int                                    /* return LESS, EQUAL or GREATER */
00520 //UNUSED spansubtract(typespan *aptr, typespan *bptr, typespan *cptr)
00521 //UNUSED {                                      /* no negative spans (whatever they * may be) */
00522 //UNUSED /* all returned tumbler values are * positive */
00523 //UNUSED 
00524 //UNUSED     int cmp = tumblercmp(&aptr->width, &bptr->width);
00525 //UNUSED     switch (cmp) {
00526 //UNUSED     case EQUAL:
00527 //UNUSED         tumblerclear(&cptr->stream);
00528 //UNUSED         tumblerclear(&cptr->width);
00529 //UNUSED         break;
00530 //UNUSED     case GREATER:
00531 //UNUSED         tumbleradd(&aptr->stream, &bptr->width, &cptr->stream);
00532 //UNUSED         tumblersub(&aptr->width, &bptr->width, &cptr->width);
00533 //UNUSED         break;
00534 //UNUSED     case LESS:
00535 //UNUSED         tumbleradd(&bptr->stream, &aptr->width, &cptr->stream);
00536 //UNUSED         tumblersub(&bptr->width, &aptr->width, &cptr->width);
00537 //UNUSED     }
00538 //UNUSED 
00539 //UNUSED     return cmp;
00540 //UNUSED }

Generated on Sun Aug 21 04:18:14 2005 for Udanax-Green by doxygen1.3.4