1: #include "../h/rt.h"
   2: #ifdef SETS
   3: 
   4: /*
   5:  * insert(S,x) - insert element x into set S if not already there
   6:  *  (always succeeds and returns S).
   7:  */
   8: 
   9: Xinsert(nargs,arg2,arg1,arg0)
  10: int nargs;
  11: struct descrip arg0, arg1, arg2;
  12:    {
  13:    register struct descrip *pd;
  14:    register int  hn;
  15:    int res;
  16:    extern struct b_selem *alcselem();
  17:    extern struct descrip *memb();
  18: 
  19:    DeRef(arg1)
  20:    DeRef(arg2)
  21:    arg0 = arg1;
  22: 
  23:    if (QUAL(arg1) || TYPE(arg1) != T_SET)
  24:       runerr(119,&arg1);
  25: 
  26:       /*
  27:       * We may need at most one new element.
  28:       */
  29:    hneed(sizeof(struct b_selem));
  30:    hn = hash(&arg2);
  31:    /*
  32:     * If arg2 is a member of set arg1 then res will have the
  33:     *  value 1 and pd will have a pointer to the descriptor
  34:     *  that points to that member.
  35:     *  If arg2 is not a member of the set then res will have
  36:     *  the value 0 and pd will point to the descriptor
  37:     *  which should point to the member - thus we know where
  38:     *  to link in the new element without having to do any
  39:     *  repetitive looking.
  40:     */
  41:    pd = memb(BLKLOC(arg1),&arg2,hn,&res);
  42:    if (res == 0)
  43:       /*
  44:       * The element is not in the set - insert it.
  45:       */
  46:       addmem(BLKLOC(arg1),alcselem(&arg2,hn),pd);
  47:    }
  48: 
  49: Procblock(insert,2)
  50: 
  51: #else SETS
  52: char junk;          /* prevent null object file  */
  53: #endif SETS

Defined functions

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