-
Notifications
You must be signed in to change notification settings - Fork 0
/
packed_edge.h
75 lines (61 loc) · 1.51 KB
/
packed_edge.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
#if !defined(PACKED_EDGE_HEADER_)
#define PACKED_EDGE_HEADER_
#ifdef GENERATOR_USE_PACKED_EDGE_TYPE
typedef struct packed_edge {
uint8_t data[5+5+1];
} packed_edge;
static inline int64_t get_v0_from_edge(const packed_edge* p) {
int64_t out = 0;
const uint8_t * restrict data = p->data;
for (int k = 0; k < 5; ++k)
out |= (int64_t)(data[k] << (8*k));
return out;
}
static inline int64_t get_v1_from_edge(const packed_edge* p) {
int64_t out = 0;
const uint8_t * restrict data = p->data;
for (int k = 0; k < 5; ++k)
out |= (int64_t)(data[5+k] << (8*k));
return out;
}
static inline uint8_t get_w_from_edge(const packed_edge* p) {
return p->data[11];
}
static inline void write_edge(packed_edge* p, int64_t v0, int64_t v1,
uint8_t w)
{
uint8_t * restrict data = p->data;
uint64_t uv0 = v0;
uint64_t uv1 = v1;
for (int k = 0; k < 5; ++k) {
data[k] = (uint8_t)(uv0 & (uint64_t)0xFF);
data[5+k] = (uint8_t)(uv1 & (uint64_t)0xFF);
uv0 >>= 8;
uv1 >>= 8;
}
data[11] = w;
}
#else
typedef struct packed_edge {
int64_t v0;
int64_t v1;
uint8_t w;
} packed_edge;
static inline int64_t get_v0_from_edge(const packed_edge* p) {
return p->v0;
}
static inline int64_t get_v1_from_edge(const packed_edge* p) {
return p->v1;
}
static inline uint8_t get_w_from_edge(const packed_edge* p) {
return p->w;
}
static inline void write_edge(packed_edge* p, int64_t v0, int64_t v1,
uint8_t w)
{
p->v0 = v0;
p->v1 = v1;
p->w = w;
}
#endif
#endif /* PACKED_EDGE_HEADER_ */