|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_COMPARATOR_H_
22 #define ELM_COMPARATOR_H_
24 #include <elm/compat.h>
25 #include <elm/string.h>
26 #include <elm/type_info.h>
27 #include <elm/util/Pair.h>
37 static inline int compare(
const T& v1,
const T& v2)
38 {
if(v1 == v2)
return 0;
else if(v1 > v2)
return 1;
else return -1; }
43 template <
class T,
class C>
47 static inline int compare(
const T& v1,
const T& v2) {
return C::compare(v1, v2); }
56 static inline int compare(
const T& v1,
const T& v2) {
return v1.compare(v2); }
57 inline int doCompare(
const T& v1,
const T& v2)
const {
return v1.compare(v2); }
63 template <
class K,
class T,
class C = Comparator<K> >
70 {
return C::compare(v1.
fst, v2. fst); }
72 {
return _c.compare(v1.
fst, v2. fst); }
73 inline int compareKey(
const K& k1,
const K& k2)
const {
return _c.doCompare(k1, k2); }
81 template <
class T,
class C>
86 static inline int compare(
const T& v1,
const T& v2)
87 {
return -C::compare(v1, v2); }
88 inline int doCompare(
const T& v1,
const T& v2)
const
89 {
return -_c.doCompare(v1, v2); }
99 static inline int compare(
const T& v1,
const T& v2)
104 template <
class T>
inline const T&
min(
const T& x,
const T& y)
106 template <
class T,
class C>
inline const T&
min(
const T& x,
const T& y,
const C& c = single<C>())
107 {
if(c.doCompare(x, y) >= 0)
return y;
else return x; }
108 template <
class T>
inline const T&
max(
const T& x,
const T& y)
110 template <
class T,
class C>
inline const T&
max(
const T& x,
const T& y,
const C& c = single<C>())
111 {
if(c.doCompare(x, y) >= 0)
return x;
else return y; }
113 template <
class C>
inline typename C::t
min(
const C& c)
114 {
typename C::Iter i(c);
typename C::t m = *i;
116 template <
class C,
class CC>
inline typename C::t
min(
const C& c,
const CC& cc)
117 {
typename C::Iter i(c);
typename C::t m = *i;
118 for(i++; i; i++)
if(cc.doCompare(*i, m) < 0) m = *i;
return m; }
119 template <
class C>
inline typename C::t
max(
const C& c)
120 {
typename C::Iter i(c);
typename C::t m = *i;
ReverseComparator(const C &c=single< C >())
Definition: compare.h:85
int doCompare(const T &v1, const T &v2) const
Definition: compare.h:39
int doCompare(const pair_t &v1, const pair_t &v2) const
Definition: compare.h:71
int doCompare(const T &v1, const T &v2) const
Definition: compare.h:88
static int compare(const T &v1, const T &v2)
Definition: compare.h:56
const T & max(const T &x, const T &y)
Definition: compare.h:108
static int compare(const pair_t &v1, const pair_t &v2)
Definition: compare.h:69
static int compare(const T &v1, const T &v2)
Definition: compare.h:47
T t
Definition: compare.h:46
const T & min(const T &x, const T &y)
Definition: compare.h:104
T t
Definition: compare.h:98
T t
Definition: compare.h:36
static int compare(const T &v1, const T &v2)
Definition: compare.h:37
AssocComparator(const C &c=single< C >())
Definition: compare.h:68
static int compare(const T &v1, const T &v2)
Definition: compare.h:86
Pair< K, T > pair_t
Definition: compare.h:66
int doCompare(const T &v1, const T &v2) const
Definition: compare.h:48
int compareKey(const K &k1, const K &k2) const
Definition: compare.h:73
T t
Definition: compare.h:84
static int compare(const T &v1, const T &v2)
Definition: compare.h:99
int doCompare(const T &v1, const T &v2) const
Definition: compare.h:57
T t
Definition: compare.h:55
pair_t t
Definition: compare.h:67
T1 fst
Definition: Pair.h:35