home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-bin.lha / lib / g++-include / gen / SLSet.ccP < prev    next >
Text File  |  1996-10-12  |  2KB  |  78 lines

  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 "<T>.SLSet.h"
  23.  
  24. int <T>SLSet::OK()
  25. {
  26.   int v = p.OK();
  27.   v &= count == p.length();
  28.   if (!v) error("invariant failure");
  29.   return v;
  30. }
  31.  
  32. Pix <T>SLSet::seek(<T&> item)
  33. {
  34.   Pix i;
  35.   for (i = p.first(); i != 0 && !<T>EQ(p(i),item); p.next(i));
  36.   return i;
  37. }
  38.  
  39. Pix <T>SLSet::add(<T&> item)
  40. {
  41.   Pix i = seek(item);
  42.   if (i == 0)
  43.   {
  44.     ++count;
  45.     i = p.append(item);
  46.   }
  47.   return i;
  48. }
  49.  
  50. void <T>SLSet::del(<T&> item)
  51. {
  52.   Pix i = p.first();
  53.   if (i == 0)
  54.     return;
  55.   else if (<T>EQ(p(i), item))
  56.   {
  57.     --count;
  58.     p.del_front();
  59.   }
  60.   else
  61.   {
  62.     Pix trail = i;
  63.     p.next(i);
  64.     while (i != 0)
  65.     {
  66.       if (<T>EQ(p(i), item))
  67.       {
  68.         --count;
  69.         p.del_after(trail);
  70.         return;
  71.       }
  72.       trail = i;
  73.       p.next(i);
  74.     }
  75.   }
  76. }    
  77.  
  78.