1: #include "../h/rt.h"
   2: #ifdef SETS
   3: 
   4: /*
   5:  * set(list) - create a set with members in list.
   6:  *  The members are linked into hash chains which are
   7:  *  arranged in increasing order by hash number.
   8:  */
   9: Xset(nargs,arg1,arg0)
  10: int nargs;
  11: struct descrip arg1, arg0;
  12:    {
  13:    register int hn;
  14:    register struct descrip *pd;
  15:    register struct b_set *ps;
  16:    union block *pb;
  17:    struct b_selem *ne;
  18:    struct descrip *pe;
  19:    int res, i, j;
  20:    extern struct descrip *memb();
  21:    extern struct b_set *alcset();
  22:    extern struct b_selem *alcselem();
  23: 
  24:    DeRef(arg1)
  25:    if (QUAL(arg1) || TYPE(arg1) != T_LIST)
  26:       runerr(108,&arg1);
  27: 
  28:    hneed(sizeof(struct b_set) + (BLKLOC(arg1)->list.cursize *
  29:       sizeof(struct b_selem)));
  30: 
  31:    pb = BLKLOC(arg1);
  32:    arg0.type = D_SET;
  33:    ps = alcset();
  34:    BLKLOC(arg0) = (union block *) ps;
  35:    /*
  36:     * Chain through each list block and for
  37:     *  each element contained in the block
  38:     *  insert the element into the set if not there.
  39:     */
  40:    for (arg1 = pb->list.listhead; arg1.type == D_LELEM;
  41:       arg1 = BLKLOC(arg1)->lelem.listnext) {
  42:          pb = BLKLOC(arg1);
  43:          for (i = 0; i < pb->lelem.nused; i++) {
  44:             j = pb->lelem.first + i;
  45:             if (j >= pb->lelem.nelem)
  46:                j -= pb->lelem.nelem;
  47:             pd = &pb->lelem.lslots[j];
  48:             pe = memb(ps, pd, hn = hash(pd), &res);
  49:             if (res == 0) {
  50:                ne = alcselem(pd,hn);
  51:                 addmem(ps,ne,pe);
  52:                 }
  53:             }
  54:       }
  55:    }
  56: 
  57: Procblock(set,1)
  58: #else SETS
  59: char junk;          /* prevent null object file  */
  60: #endif SETS

Defined functions

Procblock defined in line 57; never used
Xset defined in line 9; never used
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 846
Valid CSS Valid XHTML 1.0 Strict