modules/up/src/rpsl/gnu/SymID.Set.cc

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. seek
  2. owns
  3. clear
  4. contains
  5. error

   1 // This may look like C code, but it is really -*- C++ -*-
   2 /* 
   3 Copyright (C) 1988 Free Software Foundation
   4     written by Doug Lea (dl@rocky.oswego.edu)
   5 
   6 This file is part of the GNU C++ Library.  This library is free
   7 software; you can redistribute it and/or modify it under the terms of
   8 the GNU Library General Public License as published by the Free
   9 Software Foundation; either version 2 of the License, or (at your
  10 option) any later version.  This library is distributed in the hope
  11 that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13 PURPOSE.  See the GNU Library General Public License for more details.
  14 You should have received a copy of the GNU Library General Public
  15 License along with this library; if not, write to the Free Software
  16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17 */
  18 
  19 #ifdef __GNUG__
  20 #pragma implementation
  21 #endif
  22 #include "config.h"
  23 #include <builtin.h>
  24 #include "SymID.Set.h"
  25 
  26 
  27 Pix SymIDSet::seek(SymID  item) const
     /* [<][>][^][v][top][bottom][index][help] */
  28 {
  29   Pix i;
  30   for (i = first(); i != 0 && !(SymIDEQ((*this)(i), item)); next(i));
  31   return i;
  32 }
  33 
  34 int SymIDSet::owns(Pix idx)
     /* [<][>][^][v][top][bottom][index][help] */
  35 {
  36   if (idx == 0) return 0;
  37   for (Pix i = first(); i; next(i)) if (i == idx) return 1;
  38   return 0;
  39 }
  40 
  41 void SymIDSet::clear()
     /* [<][>][^][v][top][bottom][index][help] */
  42 {
  43   Pix i = first(); 
  44   while (i != 0)
  45   {
  46     del((*this)(i));
  47     i = first();
  48   }
  49 }
  50 
  51 int SymIDSet::contains (SymID  item) const
     /* [<][>][^][v][top][bottom][index][help] */
  52 {
  53   return seek(item) != 0;
  54 }
  55 
  56 int SymIDSet::operator <= (const SymIDSet& b) const
  57 {
  58   if (count > b.count) return 0;
  59   if (count == 0) return 1;
  60   for (Pix i = first(); i; next(i)) if (b.seek((*this)(i)) == 0) return 0;
  61   return 1;
  62 }
  63 
  64 int SymIDSet::operator == (const SymIDSet& b) const
  65 {
  66   int n = count;
  67   if (n != b.count) return 0;
  68   if (n == 0) return 1;
  69   Pix i = first();
  70   Pix j = b.first();
  71   while (n-- > 0)
  72   {
  73     if ((b.seek((*this)(i)) == 0) || (seek(b(j)) == 0)) return 0;
  74     next(i);
  75     b.next(j);
  76   }
  77   return 1;
  78 }
  79 
  80 int SymIDSet::operator != (const SymIDSet& b) const
  81 {
  82   return !(*this == b);
  83 }
  84 
  85 void SymIDSet::operator |= (SymIDSet& b)
  86 {
  87   if (&b != this)
  88     for (Pix i = b.first(); i; b.next(i)) add(b(i));
  89 }
  90 
  91 void SymIDSet::operator -= (SymIDSet& b)
  92 {
  93   if (&b == this)
  94     clear();
  95   else
  96     for (Pix i = b.first(); i; b.next(i)) del(b(i));
  97 }
  98 
  99 
 100 void SymIDSet::operator &= (SymIDSet& b)
 101 {
 102   if (&b != this)
 103   {
 104     Pix i = first();
 105     Pix n = i;
 106     while (i != 0)
 107     {
 108       next(n);
 109       if (b.seek((*this)(i)) == 0) del((*this)(i));
 110       i = n;
 111     }
 112   }
 113 }
 114 
 115 void SymIDSet::error(const char* msg) const
     /* [<][>][^][v][top][bottom][index][help] */
 116 {
 117   (*lib_error_handler)("Set", msg);
 118 }

/* [<][>][^][v][top][bottom][index][help] */