Sets v. 1.0 by Hubert Chan What it is ========== It is a simple C++ class that allows you to create sets and use normal set operations on them, including union, intersection, etc. Included is a test program (SetTest.EXE), which is an OS/2 executable. To run the program on an other system, you will have to recompile it. How to use it ============= You will have to modify Sets.HPP and recompile Sets.CPP to use it. As it is, it will create a set that can contain the elements -3,-2,...,6. To modify Sets.HPP, you just need to change NUMELEMENTS to the number of elements in the universal set, (ie. if set U had every possible element, it would have NUMELEMENTS elements in it) and MINELEMENT to the smallest possible value that could be an element in a set. eg. if in a program, you want to use the elements -45,-44,...,19,20 in a set, then you would set MINELEMENT to -45, and NUMELEMENTS to 20 - (-45) + 1 = 66. NOTE: There is no range checking performed, so trying to add an element that is ---- out of range may produce interresting effects. If you want, you can also change SETELEMENT to some other type, as long as every element that you want to use is within the range of the type. This is useful for saving memory, if, for example, you only have 5 elements in your set, and you don't want to use a whole 4 bytes (the size of in int) to refer to the elements. Make sure that it is an ordinal type. Using a non-ordinal type (eg. float, double) may produce unexpected results. You will also have to include Sets.HPP in your source files if you want to use it. There are a few ways to create a set. Doing something like Set S; will create S = { } (ie. S = the empty set). Doing something like Set S(2); will create S = { 2 } (ie. S consists of only 2). Doing something like SETELEMENT SElements[4] = { 3,5,7,1 }; Set S(4,SElements); will create S = { 3,5,7,1 } = { 1,3,5,7 }. The order of the numbers in SElements makes no difference. The 4 in S(4,SElements) is the number of elements in the array SElements. I have attempted to use the most logical operators for each set operation. I also borrowed some operators from Turbo Pascal's set type. operator(s) | meaning -------------+---------------------------------------- +,| | union of two sets *,^,& | intersection of two sets -(unary),~ | inversion (elements not in a set) -(binary) | subtraction of two sets (or S1 ^ ~S2) <= | S1 is a subset of S2 < | S1 is a proper subset of S2 >= | S1 is a superset of S2 > | S1 is a proper superset of S2 == | equivalence != | inequivalence >= can also be used to mean S1 contains element E. Disclaimer ========== If you screw up your computer while using Sets, it's not my fault. Contacting me ============= e-mail: hyc@gpu.srv.ualberta.ca or hubert@cs.ualberta.ca (I don't check this one very often) snail mail: Hubert Chan 3 Falstaff Ave. St. Albert, AB Canada, T8N 1V3 WWW: http://www.ualberta.ca/~hyc/Programming/ this page should contain the latest version of Sets. Cost ==== I'm not asking for any money from you if you want to use Sets. On the other hand, I won't complain if you really want to send me something. If you find Sets useful, please send me a note to let me know that someone is actualy using it. To come - my plans for future versions ======= in no particular order - a procedure so that 'cout << S', where S is a set, will print out the set - an overloading of the <= operator so 'E <= S' means that element E is a member of set S.