Annotation of researchv10dc/cmd/icon/src/iconx/rstruct.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * File: rstruct.c
                      3:  *  Contents: addmem, cplist, locate, memb
                      4:  */
                      5: 
                      6: #include "../h/rt.h"
                      7: /*
                      8:  * addmem - add a new set element block in the correct spot in
                      9:  *  the bucket chain.
                     10:  */
                     11: 
                     12: addmem(ps,pe,pl)
                     13: struct descrip *pl;
                     14: struct b_set *ps;
                     15: struct b_selem *pe;
                     16:    {
                     17:    ps->size++;
                     18:    if (!ChkNull(*pl) ) {
                     19:       BlkLoc(pe->clink) = BlkLoc(*pl);
                     20:       pe->clink.dword = D_Selem;
                     21:       }
                     22:    BlkLoc(*pl) = (union block *) pe;
                     23:    pl->dword = D_Selem;
                     24:    }
                     25: 
                     26: 
                     27: /*
                     28:  * cplist(d1,d2,i,j) - copy sublist d1[i:j] into d2.
                     29:  */
                     30: 
                     31: cplist(d1, d2, i, j)
                     32: struct descrip *d1, *d2;
                     33: word i, j;
                     34:    {
                     35:    register struct descrip *dp;
                     36:    word size, nelem;
                     37:    struct b_list *lp1, *lp2;
                     38:    struct b_lelem *bp1, *bp2;
                     39: 
                     40:    /*
                     41:     * Calculate the size of the sublist and fail if it's less than 0.
                     42:     *  Also round nelem up to the minimum list block size.
                     43:     */
                     44:    size = nelem = j - i;
                     45:    if (nelem < MinListSlots)
                     46:       nelem = MinListSlots;
                     47: 
                     48:    /*
                     49:     * Get pointers to the list and list elements for the source list
                     50:     *  (bp1, lp1) and the sublist (bp2, lp2).
                     51:     */
                     52:    blkreq(sizeof(struct b_list) + sizeof(struct b_lelem) +
                     53:          nelem * sizeof(struct descrip));
                     54:    lp1 = (struct b_list *) BlkLoc(*d1);
                     55:    bp1 = (struct b_lelem *) BlkLoc(lp1->listhead);
                     56:    lp2 = (struct b_list *) alclist(size);
                     57:    bp2 = (struct b_lelem *) alclstb(nelem, (word)0, size);
                     58:    lp2->listhead.dword = lp2->listtail.dword = D_Lelem;
                     59:    BlkLoc(lp2->listhead) = BlkLoc(lp2->listtail) = (union block *) bp2;
                     60:    dp = bp2->lslots;
                     61: 
                     62:    /*
                     63:     * Locate the block containing element i in the source list.
                     64:     */
                     65:    if (size > 0) {
                     66:       while (i > bp1->nused) {
                     67:          i -= bp1->nused;
                     68:          bp1 = (struct b_lelem *) BlkLoc(bp1->listnext);
                     69:          }
                     70:       }
                     71: 
                     72:    /*
                     73:     * Copy elements from the source list into the sublist, moving to
                     74:     *  the next list block in the source list when all elements in a
                     75:     *  block have been copied.
                     76:     */
                     77:    while (size > 0) {
                     78:       j = bp1->first + i - 1;
                     79:       if (j >= bp1->nelem)
                     80:          j -= bp1->nelem;
                     81:       *dp++ = bp1->lslots[j];
                     82:       if (++i > bp1->nused) {
                     83:          i = 1;
                     84:          bp1 = (struct b_lelem *) BlkLoc(bp1->listnext);
                     85:          }
                     86:       size--;
                     87:       }
                     88: 
                     89:    /*
                     90:     * Fix type and location fields for the new list.
                     91:     */
                     92:    d2->dword = D_List;
                     93:    BlkLoc(*d2) = (union block *) lp2;
                     94:    }
                     95: 
                     96: 
                     97: /*
                     98:  * locate - returns 1 if obj is in the hash chain which
                     99:  *  starts at ep in some set, returns 0 if not there
                    100:  *  (used only in diff.c and inter.c).
                    101:  */
                    102: 
                    103: locate(ep, obj)
                    104: struct b_selem *ep, *obj;
                    105:    {
                    106:    while (ep != NULL) {
                    107:       if (ep->hashnum > obj->hashnum)
                    108:           return 0;
                    109:       else if ((ep->hashnum == obj->hashnum) &&
                    110:                  (equiv(&ep->setmem, &obj->setmem)))
                    111:           return 1;
                    112:       ep = (struct b_selem *) BlkLoc(ep->clink);
                    113:       }
                    114:    return 0;
                    115:    }
                    116: 
                    117: 
                    118: /*
                    119:  * memb - sets res flag to 1 if x is a member of set S,
                    120:  *  sets res flag to 0 if not.
                    121:  *  Returns pointer to the descriptor which points to
                    122:  *  the element (or which would point to it if it were
                    123:  *  there).
                    124:  */
                    125: 
                    126: struct descrip *memb(ps,x,hn,res)
                    127: int *res;                              /* pointer to integer result flag */
                    128: struct b_set *ps;
                    129: struct descrip  *x;
                    130: word hn;
                    131:    {
                    132:     register struct descrip *lp;
                    133:     register struct b_selem  *pe;
                    134:     extern int equiv();
                    135: 
                    136:    lp = &(ps->sbucks[SlotNum(hn,SSlots)]);
                    137:    /*
                    138:     * Look for x in the hash chain.
                    139:     */
                    140:    *res = 0;
                    141:    while (BlkLoc(*lp) != NULL) {
                    142:        pe = (struct b_selem *) BlkLoc(*lp);
                    143:        if ( pe->hashnum > hn)          /* too far - it isn't there */
                    144:          return lp;
                    145:        else if (( pe->hashnum == hn ) && ( equiv(&pe->setmem, x )))  {
                    146:          *res = 1;
                    147:          return lp;
                    148:          }
                    149:    /*
                    150:     * We haven't reached the right hashnumber yet or
                    151:     *  the element isn't the right one so keep looking.
                    152:     */
                    153:       lp = &(pe->clink);
                    154:    }
                    155:    /*
                    156:     *  At end of chain - not there.
                    157:     */
                    158:    return lp;
                    159:    }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.