1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * x -- y - difference of csets x and y or of sets x and y.
   5:  */
   6: 
   7: diff(nargs, arg2, arg1, arg0)
   8: int nargs;
   9: struct descrip arg2, arg1, arg0;
  10:    {
  11:    register int i;
  12:    register union block *bp;
  13:    int *cs1, *cs2, csbuf1[CSETSIZE], csbuf2[CSETSIZE];
  14:    extern struct b_cset *alccset();
  15: #ifdef SETS
  16:    struct descrip *dp;
  17:    struct b_set *srcp, *dstp, *tstp;
  18:    struct b_selem *sep;
  19:    extern struct b_set *alcset();
  20:    extern struct b_selem *alcselem();
  21: #endif SETS
  22: 
  23:    SetBound;
  24: #ifdef SETS
  25:    DeRef(arg1)
  26:    DeRef(arg2)
  27:    if (QUAL(arg1) || QUAL(arg2))
  28:       goto skipsets;
  29:    if (TYPE(arg1) == T_SET && TYPE(arg2) != T_SET)
  30:       runerr(119,&arg2);
  31:    if (TYPE(arg2) == T_SET && TYPE(arg1) != T_SET)
  32:       runerr(119,&arg1);
  33:    if (TYPE(arg1) == T_SET && TYPE(arg2) == T_SET) {
  34:       /*
  35:        * Both x and y are sets - do set difference
  36:        *  get enough space for a new set the size of x.
  37:        */
  38:       hneed(sizeof(struct b_set) + BLKLOC(arg1)->set.setsize *
  39:          sizeof(struct b_selem));
  40:       /*
  41:        * For each element in set x if it isn't in set y
  42:        *  copy it directly into the result set.
  43:        */
  44:       srcp = (struct b_set *) BLKLOC(arg1);
  45:       tstp = (struct b_set *) BLKLOC(arg2);
  46:       arg0.type = D_SET;
  47:       dstp = alcset();
  48:       BLKLOC(arg0) = (union block *) dstp;
  49:       for (i = 0; i < NBUCKETS; i++) {
  50:          sep = (struct b_selem *) BLKLOC(srcp->sbucks[i]);
  51:          dp = &dstp->sbucks[i];
  52:          while (sep != NULL) {
  53:             if ( !locate( BLKLOC(tstp->sbucks[i]), sep) ) {
  54:                dp->type = D_SELEM;
  55:                BLKLOC(*dp) = (union block *) alcselem(&sep->setmem, sep->hnum);
  56:                dp = &BLKLOC(*dp)->selem.sblink;
  57:                dstp->setsize++;
  58:                }
  59:             sep = (struct b_selem *) BLKLOC(sep->sblink);
  60:             }
  61:          }
  62:       }
  63:    else {
  64:       skipsets:
  65: #endif SETS
  66:    hneed(sizeof(struct b_cset));
  67: 
  68:    /*
  69:     * x and y must be csets.
  70:     */
  71:    if (cvcset(&arg1, &cs1, csbuf1) == NULL)
  72:       runerr(104, &arg1);
  73:    if (cvcset(&arg2, &cs2, csbuf2) == NULL)
  74:       runerr(104, &arg2);
  75: 
  76:    /*
  77:     * Allocate a new cset and in each word of it, compute the value
  78:     *  of the bitwise difference of the corresponding words in the
  79:     *  x and y csets.
  80:     */
  81:    bp = (union block *) alccset();
  82:    for (i = 0; i < CSETSIZE; i++)
  83:       bp->cset.bits[i] = cs1[i] & ~cs2[i];
  84: 
  85:    arg0.type = D_CSET;
  86:    BLKLOC(arg0) = bp;
  87: #ifdef SETS
  88:    }
  89: #endif SETS
  90:    ClearBound;
  91:    }
  92: 
  93: Opblock(diff,2,"--")

Defined functions

diff defined in line 7; used 1 times
  • in line 93
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 576
Valid CSS Valid XHTML 1.0 Strict