00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <limits>
00015 #include <stxxl/types>
00016
00017
00018 template <typename KEY, unsigned SIZE>
00019 struct my_type
00020 {
00021 typedef KEY key_type;
00022
00023 key_type _key;
00024 char _data[SIZE - sizeof(key_type)];
00025
00026 my_type() { }
00027 my_type(key_type __key) : _key(__key) { }
00028
00029 #ifdef KEY_COMPARE
00030 key_type key() const
00031 {
00032 return _key;
00033 }
00034 #endif
00035
00036 static my_type<KEY, SIZE> min_value()
00037 {
00038 return my_type<KEY, SIZE>(std::numeric_limits<key_type>::min());
00039 }
00040 static my_type<KEY, SIZE> max_value()
00041 {
00042 return my_type<KEY, SIZE>(std::numeric_limits<key_type>::max());
00043 }
00044 };
00045
00046 template <typename KEY, unsigned SIZE>
00047 std::ostream & operator << (std::ostream & o, const my_type<KEY, SIZE> obj)
00048 {
00049 #ifndef KEY_COMPARE
00050 o << obj._key;
00051 #else
00052 o << obj.key();
00053 #endif
00054 return o;
00055 }
00056
00057 #ifndef KEY_COMPARE
00058
00059 template <typename KEY, unsigned SIZE>
00060 bool operator < (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
00061 {
00062 return a._key < b._key;
00063 }
00064
00065 template <typename KEY, unsigned SIZE>
00066 bool operator == (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
00067 {
00068 return a._key == b._key;
00069 }
00070
00071 template <typename KEY, unsigned SIZE>
00072 bool operator != (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
00073 {
00074 return a._key != b._key;
00075 }
00076
00077 template <typename T>
00078 struct Cmp : public std::less<T>
00079 {
00080 bool operator () (const T & a, const T & b) const
00081 {
00082 return a._key < b._key;
00083 }
00084
00085 static T min_value()
00086 {
00087 return T::min_value();
00088 }
00089 static T max_value()
00090 {
00091 return T::max_value();
00092 }
00093 };
00094
00095 #else
00096
00097 template <typename KEY, unsigned SIZE>
00098 bool operator < (const my_type<KEY, SIZE> & a, const my_type<KEY, SIZE> & b)
00099 {
00100 return a.key() < b.key();
00101 }
00102
00103 #endif
00104
00105 struct zero
00106 {
00107 unsigned operator () ()
00108 {
00109 return 0;
00110 }
00111 };