home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / base / intset.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  2KB  |  96 lines

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  *
  7.  *          Copyright (C) 1994, M. A. Sridhar
  8.  *  
  9.  *
  10.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  11.  *     to copy, modify or distribute this software  as you see fit,
  12.  *     and to use  it  for  any  purpose, provided   this copyright
  13.  *     notice and the following   disclaimer are included  with all
  14.  *     copies.
  15.  *
  16.  *                        DISCLAIMER
  17.  *
  18.  *     The author makes no warranties, either expressed or implied,
  19.  *     with respect  to  this  software, its  quality, performance,
  20.  *     merchantability, or fitness for any particular purpose. This
  21.  *     software is distributed  AS IS.  The  user of this  software
  22.  *     assumes all risks  as to its quality  and performance. In no
  23.  *     event shall the author be liable for any direct, indirect or
  24.  *     consequential damages, even if the  author has been  advised
  25.  *     as to the possibility of such damages.
  26.  *
  27.  */
  28.  
  29.  
  30.  
  31.  
  32.  
  33. #ifdef __GNUC__
  34. #pragma implementation
  35. #endif
  36.  
  37.  
  38.  
  39. #include "base/setimp.cxx"
  40.  
  41.  
  42.  
  43.  
  44.  
  45. #if defined(__GNUC__) && __GNUC_MINOR__ >= 6
  46. template class CL_Set<long>;
  47. template class CL_Iterator<long>;
  48. template class CL_SetIterator<long>;
  49. #endif
  50.  
  51. #include "base/string.h"
  52. #include "base/intset.h"
  53. #include "base/sequence.h"
  54.  
  55.  
  56.  
  57.  
  58. CL_DEFINE_CLASS(CL_IntegerSet, _CL_IntegerSet_CLASSID);
  59.  
  60.  
  61. CL_IntegerSet::CL_IntegerSet (long lo, long hi)
  62. {
  63.     for (long i = lo; i <= hi; i++)
  64.         Add (i);
  65. }
  66.  
  67.  
  68. CL_String CL_IntegerSet::AsString() const
  69. {
  70.     if (!_idata)
  71.         return  "{}";
  72.     CL_String s ("{");
  73.     long n = Size();
  74.     for (long i = 0; i < n; i++) {
  75.         s += CL_String (ItemWithRank (i));
  76.         if (i < n-1)
  77.             s += ", ";
  78.     }
  79.     s += "}";
  80.     return s;
  81. }
  82.  
  83. long CL_IntegerSet::SmallestNonMember () const
  84. {
  85.     long n = Size();
  86.     if (n <= 0)
  87.         return -1;
  88.     for (long i = 0; i < n; i++)
  89.         if (ItemWithRank(i) != i)
  90.             break;
  91.     return i;
  92. }
  93.  
  94.  
  95.  
  96.