-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtypes.h
190 lines (179 loc) · 3.95 KB
/
types.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* ===============================================================
* Description: Data types in Weaver.
*
* Created: 2014-07-07 13:17:21
*
* Author: Ayush Dubey, [email protected]
*
* Copyright (C) 2013, Cornell University, see the LICENSE file
* for licensing agreement
* ===============================================================
*/
#ifndef weaver_common_types_h_
#define weaver_common_types_h_
#include "common/utils.h"
//#define weaver_strict_type_check_
#ifdef weaver_strict_type_check_
#include <e/buffer.h>
#define WEAVER_UINT64(TYPE) \
struct TYPE \
{ \
uint64_t value; \
\
TYPE(uint64_t v) : value(v) { } \
\
TYPE& operator=(TYPE rhs) \
{ \
value = rhs.value; \
return *this; \
} \
\
TYPE& operator++() \
{ \
value++; \
return *this; \
} \
\
TYPE operator++(int) \
{ \
TYPE tmp \
tmp.value = value; \
operator++(); \
return tmp; \
} \
\
TYPE& operator--() \
{ \
value--; \
return *this; \
} \
\
TYPE operator--(int) \
{ \
TYPE tmp \
tmp.value = value; \
operator--(); \
return tmp; \
} \
\
TYPE& operator+=(const TYPE &rhs) \
{ \
value += rhs.value; \
return *this; \
} \
\
TYPE& operator-=(const TYPE &rhs) \
{ \
value -= rhs.value; \
return *this; \
} \
\
}; \
\
inline std::ostream& \
operator<<(std::ostream& os, const TYPE &t) \
{ \
os << t.value; \
return os; \
} \
\
inline std::istream& \
operator>>(std::istream& is, TYPE &t) \
{ \
is >> t.value; \
return is; \
} \
\
inline bool \
operator==(const TYPE& lhs, const TYPE& rhs) \
{ \
return lhs.value == rhs.value; \
} \
\
inline bool \
operator!=(const TYPE& lhs, const TYPE& rhs) \
{ \
return !operator==(lhs,rhs); \
} \
\
inline bool \
operator< (const TYPE& lhs, const TYPE& rhs) \
{ \
return lhs.value < rhs.value; \
} \
\
inline bool \
operator> (const TYPE& lhs, const TYPE& rhs) \
{ \
return operator< (rhs,lhs); \
} \
\
inline bool \
operator<=(const TYPE& lhs, const TYPE& rhs) \
{ \
return !operator> (lhs,rhs); \
} \
\
inline bool \
operator>=(const TYPE& lhs, const TYPE& rhs) \
{ \
return !operator< (lhs,rhs); \
} \
\
inline TYPE operator+(TYPE lhs, const TYPE& rhs) \
{ \
lhs += rhs; \
return lhs; \
} \
\
inline TYPE operator-(TYPE lhs, const TYPE& rhs) \
{ \
lhs -= rhs; \
return lhs; \
} \
\
namespace std \
{ \
template <> \
struct hash<TYPE> \
{ \
size_t operator()(const TYPE& k) const \
{ \
return hash<uint64_t>()(k.value); \
} \
}; \
} \
\
namespace message \
{ \
uint64_t size(const TYPE &t) \
{ \
return sizeof(uint64_t); \
} \
\
void pack_buffer(e::packer &packer, const TYPE &t) \
{ \
packer << t.value; \
} \
\
void unpack_buffer(e::unpacker &unpacker, TYPE &t) \
{ \
unpacker >> t.value; \
} \
}
WEAVER_UINT64(node_id_t);
WEAVER_UINT64(cache_key_t);
typedef std::string node_handle_t;
typedef std::string edge_handle_t;
#else
typedef std::string node_handle_t;
typedef std::string edge_handle_t;
typedef std::string cache_key_t;
inline uint64_t
hash_node_handle(const node_handle_t &nh)
{
return weaver_util::murmur_hasher<std::string>()(nh);
}
#endif
#endif