home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sets115.zip / Sets.txt < prev    next >
Text File  |  1997-05-24  |  7KB  |  148 lines

  1.                                   Sets v. 1.15
  2.                                  by Hubert Chan
  3.  
  4. What it is
  5. ==========
  6.   It is a simple C++ class that allows you to create sets and use normal set
  7. operations on them, including union, intersection, etc.  It should work with
  8. any compiler that accepts the C++ 2.0 standard.
  9.   Included is a test program (SetTest.exe), which is an OS/2 executable (the
  10. emx 0.8 runtime environment is required).  To run the program on an other
  11. system, you will have to recompile it.
  12.   The included makefile was made for emx 0.8 and dmake.  It should be fairly
  13. easy to modify it to suit your compiler.
  14.  
  15. How to use it
  16. =============
  17.   You will have to modify Sets.hpp and recompile Sets.cpp to use it.  As it is,
  18. it will create a set that can contain the elements -3,-2,...,6.  To modify
  19. Sets.hpp, you just need to change MINELEMENT and MAXELEMENT to the smallest and
  20. largest possible values (respectively) that could be an element in a set.
  21.  
  22.   eg. if in a program, you want to use the elements -45,-44,...,19,20 in a set,
  23. then you would set MINELEMENT to -45, and MAXELEMENT to 20.
  24.  
  25.   These values are only used to conserve memory.  For example, if you want to
  26. have a set of numbers ranging from 300 - 350, you would have to use at least a
  27. 'short' type (ie. 2 bytes).  A set of 'short' values would take 65536 / 8 = 8192
  28. bytes, or 8 kb.  However, with MINELEMENT and MAXELEMENT set properly, it would
  29. only take 50 / 8 = 7 bytes < 1 kb, saving over 7 kb of memory.  If you had a
  30. bunch of sets, the gain would be even greater.
  31.  
  32. NOTE: There is no range checking performed, so trying to add an element that is
  33. ----  out of range may produce interresting effects.
  34.  
  35.   If you want, you can also change Set::SetElement to some other type, as long
  36. as every element that you want to use is within the range of the type.  This is
  37. useful for saving memory, if, for example, you only have 5 elements in your
  38. set, and you don't want to use a whole 2 bytes (the size of in int on some
  39. systems) to refer to the elements.  Make sure that it is an ordinal type.
  40. Using a non-ordinal type (eg. float, double) may produce unexpected results.
  41.  
  42.   You will also have to include Sets.hpp in your source files if you want to
  43. use it.
  44.   There are a few ways to create a set.
  45.         Set S1;                   // creates S1 = { } = the empty set
  46.         Set S2(2);                // creates S2 = { 2 }
  47.         Set::SetElement SElements[4] = { 3,5,7,1 };
  48.         Set S3(4,SElements);      // creates S3 = { 3,5,7,1 } = { 1,3,5,7 }
  49.           (The order of the numbers in SElements makes no difference.  The 4
  50.           in S(4,SElements) is the number of elements in the array SElements. )
  51.  
  52.   I have attempted to use the most logical operators for each set operation.  I
  53. also borrowed some operators from Turbo Pascal's set type.
  54.  
  55. The following table shows the operators and their meaning.  My home page has
  56. the same table, along with the meanings written in 'standard' mathematical
  57. notation (see below under 'Contacting me' for my home page).
  58.     operator(s) |   meaning
  59.    -------------+----------------------------------------
  60.         +,|     |  union of two sets
  61.        *,^,&    |  intersection of two sets
  62.     -(unary),~  |  complement (elements not in a set)
  63.      -(binary)  |  difference of two sets (or  S1 ^ ~S2)
  64.          <=     |  S1 is a subset of S2
  65.          <      |  S1 is a proper subset of S2
  66.          >=     |  S1 is a superset of S2
  67.          >      |  S1 is a proper superset of S2
  68.          ==     |  equivalence
  69.          !=     |  inequivalence
  70.  
  71.   >= can also be used to mean S1 contains element E.
  72.   <= can also be used to mean E is an element in S1
  73.   S1.Card() indicates the cardinality of set S1 (the number of elements in S1)
  74.  
  75. Disclaimer
  76. ==========
  77.   If you screw up your computer while using Sets, it's not my fault.
  78.  
  79. WARNING: Sets uses pointers, and performs no range checking whatsoever (in the
  80. interests of speed).  In order to ensure that you don't screw up your computer
  81. by accessing memory that you're not supposed to, you will have to do your own
  82. range checking.
  83.  
  84. Contacting me
  85. =============
  86. e-mail: hyc@gpu.srv.ualberta.ca
  87.    or   hubert@cs.ualberta.ca (I don't check this one very often)
  88.  
  89. snail mail:
  90.   Hubert Chan
  91.   3 Falstaff Ave.
  92.   St. Albert, AB
  93.   Canada, T8N 1V3
  94.  
  95. WWW: http://www.ualberta.ca/~hyc/Programming/
  96.      this page should contain the latest version of Sets.
  97.  
  98. Cost
  99. ====
  100.   I'm not asking for any money from you if you want to use Sets.  On the other
  101. hand, I won't complain if you really want to send me something.
  102.   If you find Sets useful, please send me a note to let me know that someone is
  103. actualy using it.
  104.  
  105. History
  106. =======
  107. I would like to thank Darin McBride for his suggestions.  Some I have
  108. implemented, some will be implemented in future versions.
  109.  
  110. changes from version 1.1
  111. - added a function to determine the cardinality of a set.
  112.  
  113. - renamed the files to have lower case extensions (as UNIX usually does it),
  114.   and fixed some things to make it work better in case-sensitive file systems.
  115.  
  116. changes from version 1.0
  117. - now you can use 'E <= S' to mean 'E is an element of set S'.  As well, some
  118.   operators have been overloaded to accept elements as rvalues, instead of
  119.   converting them to sets first.
  120.  
  121. - now you set MINELEMENT and MAXELEMENT instead of MINELEMENT and NUMELEMENT.
  122.   NUMELEMENT is now calculated from MINELEMENT and MAXELEMENT.
  123.  
  124. - SetElement is now a public type in the Set class.
  125.  
  126. - There is now a << operator to concatenate a set with a string. (for doing
  127.   things like 'cout << "This is a set: " << S1;' )  Unfortunately, I don't have
  128.   the full C++ package on my computer, so I can't test it.  If you want to try
  129.   it out, it is at the bottom of the Sets.CPP file, commented out.  You will
  130.   also have to uncomment the line in Sets.HPP declaring '<<' as a friend, and
  131.   uncomment the #include statement at the top of Sets.HPP.
  132.  
  133. - added a copy initializer Set(Set &).
  134.  
  135. To come - my plans for future versions
  136. =======
  137. in no particular order
  138. - make Sets a template to make it more versatile / easy to use
  139. - allow Sets to use user defined types.  Maybe allow sets of complex numbers,
  140.   polynomials, etc.  (OK, so this might be a bit too ambitious)
  141. - create a class that would allow the creation of mathematical groups, rings,
  142.   and fields (finite, of course).
  143. - make MINELEMENT and MAXELEMENT local in the Set class (instead of making them
  144.   '#define'd constants).  Shouldn't be too hard to do, but my compiler just
  145.   won't accept it for some reason.
  146. - any suggestions you have
  147.  
  148.