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