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