00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016
00017 #include <stxxl/io>
00018 #include <stxxl/mng>
00019 #include <stxxl/ksort>
00020 #include <stxxl/sort>
00021 #include <stxxl/vector>
00022
00023
00024 struct my_type
00025 {
00026 typedef unsigned key_type;
00027
00028 key_type _key;
00029 char _data[128 - sizeof(key_type)];
00030 key_type key() const
00031 {
00032 return _key;
00033 }
00034
00035 my_type() { }
00036 my_type(key_type __key) : _key(__key) { }
00037
00038 static my_type min_value()
00039 {
00040 return my_type((std::numeric_limits<key_type>::min)());
00041 }
00042 static my_type max_value()
00043 {
00044 return my_type((std::numeric_limits<key_type>::max)());
00045 }
00046 };
00047
00048
00049 bool operator < (const my_type & a, const my_type & b)
00050 {
00051 return a.key() < b.key();
00052 }
00053
00054 struct Cmp
00055 {
00056 bool operator () (const my_type & a, const my_type & b) const
00057 {
00058 return a < b;
00059 }
00060 static my_type min_value()
00061 {
00062 return my_type::min_value();
00063 }
00064 static my_type max_value()
00065 {
00066 return my_type::max_value();
00067 }
00068 };
00069
00070 std::ostream & operator << (std::ostream & o, const my_type & obj)
00071 {
00072 o << obj._key;
00073 return o;
00074 }
00075
00076 int main()
00077 {
00078 stxxl::syscall_file f("./in", stxxl::file::DIRECT | stxxl::file::RDWR);
00079
00080 unsigned memory_to_use = 50 * 1024 * 1024;
00081 typedef stxxl::vector<my_type> vector_type;
00082 {
00083 vector_type v(&f);
00084
00085
00086
00087
00088
00089
00090
00091 STXXL_MSG("Checking order...");
00092 STXXL_MSG(((stxxl::is_sorted(v.begin(), v.end())) ? "OK" : "WRONG"));
00093
00094 STXXL_MSG("Sorting...");
00095 stxxl::ksort(v.begin(), v.end(), memory_to_use);
00096
00097
00098 STXXL_MSG("Checking order...");
00099 STXXL_MSG(((stxxl::is_sorted(v.begin(), v.end())) ? "OK" : "WRONG"));
00100 }
00101 STXXL_MSG("OK");
00102
00103 return 0;
00104 }