home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / libg++-2.5.3-bin.lha / lib / g++-include / gen / SLBag.ccP < prev    next >
Text File  |  1994-02-21  |  2KB  |  106 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, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19. #ifdef __GNUG__
  20. #pragma implementation
  21. #endif
  22. #include "<T>.SLBag.h"
  23.  
  24. int <T>SLBag::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>SLBag::seek(<T&> item, Pix i)
  33. {
  34.   if (i == 0) i = first(); else next(i);
  35.   for (; i != 0 && (!(<T>EQ(p(i), item))); p.next(i));
  36.   return i;
  37. }
  38.  
  39. int <T>SLBag::nof(<T&> item)
  40. {
  41.   int n = 0;
  42.   for (Pix p = first(); p; next(p)) if (<T>EQ((*this)(p), item)) ++n;
  43.   return n;
  44. }
  45.  
  46.  
  47. void <T>SLBag::del(<T&> item)
  48. {
  49.   Pix i = p.first();
  50.   if (i == 0) 
  51.     return;
  52.   else if (<T>EQ(p(i), item))
  53.   {
  54.     --count;
  55.     p.del_front();
  56.   }
  57.   else
  58.   {
  59.     Pix trail = i;
  60.     p.next(i);
  61.     while (i != 0)
  62.     {
  63.       if (<T>EQ(p(i), item))
  64.       {
  65.         --count;
  66.         p.del_after(trail);
  67.         return;
  68.       }
  69.       trail = i;
  70.       p.next(i);
  71.     }
  72.   }
  73. }    
  74.  
  75. void <T>SLBag::remove(<T&> item)
  76. {
  77.   Pix i = p.first();
  78.   while (i != 0 && <T>EQ(p(i), item))
  79.   {
  80.     --count;
  81.     p.del_front();
  82.     i = p.first();
  83.   }
  84.   if (i != 0)
  85.   {
  86.     Pix trail = i;
  87.     p.next(i);
  88.     while (i != 0)
  89.     {
  90.       if (<T>EQ(p(i), item))
  91.       {
  92.         --count;
  93.         p.del_after(trail);
  94.         i = trail;
  95.         p.next(i);
  96.       }
  97.       else
  98.       {
  99.         trail = i;
  100.         p.next(i);
  101.       }
  102.     }
  103.   }
  104. }    
  105.  
  106.