00001 00002 #include <iostream> 00003 00004 #include <boost/timer.hpp> 00005 #include <boost/numeric/ublas/vector.hpp> 00006 #include <boost/numeric/ublas/storage.hpp> 00007 #include <boost/numeric/ublas/io.hpp> 00008 00009 using std::size_t; 00010 using std::cout; 00011 using std::endl; 00012 00013 using namespace boost::numeric::ublas; 00014 00015 int main(size_t argc, char *argv[]) 00016 { 00017 size_t size = 20; 00018 00019 if (argc > 1) 00020 size = ::atoi (argv [1]); 00021 00022 typedef vector <size_t> V1; 00023 typedef vector <size_t> V2; 00024 typedef vector <double> V3; 00025 00026 V1 v1(size); 00027 V2 v2(size); 00028 V3 v3(size); 00029 00030 for (size_t i=0; i<size; ++i) { 00031 v1(i) = (5*i+3) % size; 00032 v2(i) = (7*i+1) % size; 00033 v3(i) = i; 00034 } 00035 00036 if (size < 200) { 00037 cout << v1 << endl; 00038 cout << v2 << endl; 00039 cout << v3 << endl; 00040 } 00041 00042 boost::timer t; 00043 00044 t.restart(); 00045 index_triple_array<V1, V2, V3> ita(size,v1,v2,v3); 00046 std::sort(ita.begin(), ita.end()); 00047 00048 cout << "sort time " << t.elapsed() << endl; 00049 00050 if (size < 200) { 00051 cout << v1 << endl; 00052 cout << v2 << endl; 00053 cout << v3 << endl; 00054 } 00055 00056 std::sort(v3.begin(), v3.end()); 00057 bool ok = true; 00058 if (v3(0) == 0) { 00059 for (size_t i=1; i < size; ++i) { 00060 if ( (v1(i-1) > v1(i)) || 00061 (v1(i-1) == v1(i) && v2(i-1) > v2(i) ) ) { 00062 cout << "wrong order: " << i << endl; 00063 ok = false; 00064 break; 00065 } 00066 if (v3(i) != i) { 00067 ok = false; 00068 cout << "lost data: " << i << endl; 00069 break; 00070 } 00071 } 00072 } else { 00073 ok = false; 00074 cout << "lost data: 0" << endl; 00075 } 00076 00077 cout << (ok?"ok":"not ok") << endl; 00078 00079 };