-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.h
124 lines (99 loc) · 3.16 KB
/
common.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
#ifndef SORT_MERGE_JOIN__COMMON_H_
#define SORT_MERGE_JOIN__COMMON_H_
#define DEBUG 1
#define LOG 0
#if DEBUG
#include <cassert>
#else
#define assert(emtpy_cond)
#endif
#include <cstdint>
#include <cstdio>
#include <utility>
#include <type_traits>
#include "metaprogramming.h"
using i64 = int64_t;
using u32 = uint32_t;
using i32 = int32_t;
using u16 = uint16_t;
using i16 = int16_t;
using u8 = uint8_t;
using i8 = int8_t;
using byte = i8;
// A custom uint64_t. Mainly to add a utility that gets
// a specific byte without weird macros.
struct u64 {
uint64_t v;
template<typename T, enable_if_integral_t<T> = true>
u64(T value) {
this->v = value;
}
template<typename T, enable_if_integral_t<T> = true>
__always_inline u64 &operator=(T value) {
v = value;
return *this;
}
template<typename T, enable_if_integral_t<T> = true>
operator T() { return v; }
__always_inline u8 byte(size_t i) const {
assert(i < 8);
return (v >> ((7U - i) * 8U)) & 0xFFU;
}
__always_inline bool operator==(const u64 rhs) const {
return v == rhs.v;
}
__always_inline bool operator!=(const u64 rhs) const {
return v != rhs.v;
}
__always_inline bool operator<(const u64 rhs) const {
return v < rhs.v;
}
__always_inline bool operator>(const u64 rhs) const {
return v > rhs.v;
}
__always_inline bool operator<=(const u64 rhs) const {
return v <= rhs.v;
}
__always_inline bool operator>=(const u64 rhs) const {
return v >= rhs.v;
}
__always_inline u64 operator+(const u64 rhs) const {
return v + v;
}
};
#define DEFAULT_CONSTRUCTOR(Typename) Typename() = default;
#define DEFAULT_COPY(Typename) \
Typename(const Typename &rhs) = default; \
Typename &operator=(const Typename &rhs) = default;
#define DEFAULT_MOVE(Typename) \
Typename(Typename &&rhs) noexcept = default; \
Typename &operator=(Typename &&rhs) noexcept = default;
#define DEFAULT_COPY_AND_MOVE(Typename) \
DEFAULT_COPY(Typename) \
DEFAULT_MOVE(Typename)
#define DEFAULT_CONSTRUCT(Typename) \
DEFAULT_CONSTRUCTOR(Typename) \
DEFAULT_COPY_AND_MOVE(Typename)
#if LOG
// Fight the preprocessor.
struct RelationColumns;
struct ColumnStore;
struct Relation;
struct MinMaxPair;
void log(const char *fmt, ...);
void red_on();
void red_off();
void yellow_on();
void yellow_off();
void bold_on();
void bold_off();
void print_pointer(size_t i, size_t j);
void print_pointed_columns_and_hist(RelationColumns r, size_t i,
size_t hist[256], int byte_pos,
size_t just_changed);
void print_pointed_histogram(const size_t hist[256], int i,
ColumnStore *prefix_sum[256], MinMaxPair minmax);
void print_r_and_aux(RelationColumns r, RelationColumns s, size_t i,
size_t just_changed, int byte_pos);
#endif
#endif