00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <iostream>
00037 #include <algorithm>
00038 #include <vector>
00039 #include <list>
00040
00041 using std::vector;
00042 using std::list;
00043
00044
00045 #ifdef BM_NO_STL
00046 # undef BM_NO_STL
00047 #endif
00048
00049 #include "bm.h"
00050
00051 using namespace std;
00052
00053 void Print(unsigned n)
00054 {
00055 cout << n << endl;;
00056 }
00057
00058
00059 template<class T> void PrintContainer(T first, T last)
00060 {
00061 if (first == last)
00062 cout << "<EMPTY SET>";
00063 else
00064 for(;first != last; ++first)
00065 cout << *first << ";";
00066 cout << endl;
00067 }
00068
00069 int main(void)
00070 {
00071 bm::bvector<> bv;
00072
00073 bv[10] = true;
00074 bv[100] = true;
00075 bv[10000] = true;
00076
00077 cout << "Source set:";
00078 PrintContainer(bv.first(), bv.end());
00079
00080
00081 {
00082 vector<unsigned> vect;
00083 vect.resize(bv.count());
00084 std::copy(bv.first(), bv.end(), vect.begin());
00085 cout << "Vector:";
00086 PrintContainer(vect.begin(), vect.end());
00087 }
00088
00089
00090
00091 {
00092 list<unsigned> lst;
00093 std::copy(bv.first(), bv.end(), std::back_inserter(lst));
00094 cout << "List:";
00095 PrintContainer(lst.begin(), lst.end());
00096 }
00097
00098 {
00099 vector<unsigned> vect;
00100 vector<unsigned> res1, res2, res3;
00101
00102 vect.push_back(100);
00103 vect.push_back(15);
00104 vect.push_back(150);
00105
00106 cout << "Argument vector for set operations:";
00107 PrintContainer(vect.begin(), vect.end());
00108
00109
00110 std::sort(vect.begin(), vect.end());
00111 cout << endl;
00112
00113 std::set_union(bv.first(), bv.end(),
00114 vect.begin(), vect.end(),
00115 std::back_inserter(res1));
00116 cout << "Set union:" << endl;
00117 PrintContainer(res1.begin(), res1.end());
00118
00119 std::set_intersection(bv.first(), bv.end(),
00120 vect.begin(), vect.end(),
00121 std::back_inserter(res2));
00122 cout << "Set intersection:" << endl;
00123 PrintContainer(res2.begin(), res2.end());
00124
00125 vector<unsigned>::const_iterator it1 = vect.begin();
00126 vector<unsigned>::const_iterator it2 = vect.end();
00127 bm::bvector<>::enumerator en = bv.first();
00128 bm::bvector<>::enumerator en2= bv.end();
00129
00130 std::set_difference(en, en2,
00131 it1, it2,
00132 std::back_inserter(res3));
00133
00134 cout << "Set diff:" << endl;
00135 PrintContainer(res3.begin(), res3.end());
00136
00137 }
00138
00139
00140 {
00141 bm::bvector<> bv1;
00142 std::vector<unsigned> vect;
00143
00144 vect.push_back(300);
00145 vect.push_back(200);
00146 vect.push_back(275);
00147 vect.push_back(200);
00148
00149 cout << endl << "Source vector:";
00150 PrintContainer(vect.begin(), vect.end());
00151
00152
00153
00154
00155 std::copy(vect.begin(), vect.end(), bv1.inserter());
00156 cout << "Bitset:";
00157
00158 PrintContainer(bv1.first(), bv1.end());
00159 }
00160
00161
00162 return 0;
00163 }
00164