-
Notifications
You must be signed in to change notification settings - Fork 77
/
predefined.h
48 lines (38 loc) · 971 Bytes
/
predefined.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef PREDEFINED_H
#define PREDEFINED_H
#include <string.h>
namespace bpt {
/* predefined B+ info */
#define BP_ORDER 20
/* key/value type */
typedef int value_t;
struct key_t {
char k[16];
key_t(const char *str = "")
{
bzero(k, sizeof(k));
strcpy(k, str);
}
operator bool() const {
return strcmp(k, "");
}
};
inline int keycmp(const key_t &a, const key_t &b) {
int x = strlen(a.k) - strlen(b.k);
return x == 0 ? strcmp(a.k, b.k) : x;
}
#define OPERATOR_KEYCMP(type) \
bool operator< (const key_t &l, const type &r) {\
return keycmp(l, r.key) < 0;\
}\
bool operator< (const type &l, const key_t &r) {\
return keycmp(l.key, r) < 0;\
}\
bool operator== (const key_t &l, const type &r) {\
return keycmp(l, r.key) == 0;\
}\
bool operator== (const type &l, const key_t &r) {\
return keycmp(l.key, r) == 0;\
}
}
#endif /* end of PREDEFINED_H */