-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathConstant.h
114 lines (107 loc) · 3.27 KB
/
Constant.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
//
// Created by tangdingyi on 2019/12/25.
//
#ifndef MPC_ML_CONSTANT_H
#define MPC_ML_CONSTANT_H
#ifndef UNIX_PLATFORM
#define UNIX_PLATFORM
#endif
//#ifndef MAC_OS
//#define MAC_OS
//#endif
#include "config/Config.hpp"
#include <iostream>
#include <cstdio>
#include <vector>
#include <fstream>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <chrono>
#include <cmath>
#include <limits>
#ifdef UNIX_PLATFORM
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#else
#include <winsock2.h>
#endif
#define DEBUG
#ifdef DEBUG
#define DBGprint(...) printf(__VA_ARGS__)
#else
#define DBGprint(...)
#endif
using namespace std;
using namespace chrono;
typedef long long ll; // 64-bit
typedef __int128_t ll128; // 128-bit
typedef __float128 ff128;
extern int node_type;
extern int globalRound;
extern int DBGtest;
class Constant {
public:
static string getDateTime() {
time_t t = std::time(nullptr);
struct tm * now = localtime(&t);
char buf[80];
strftime(buf, sizeof(buf), "%Y-%m-%d_%H-%M-%S", now);
return string(buf);
}
class Clock {
int id;
system_clock::time_point start;
static ll global_clock[101];
public:
static double get_clock(int id);
static void print_clock(int id);
Clock(int id) : id(id) {
start = system_clock::now();
};
~Clock() {
system_clock::time_point end = system_clock::now();
decltype(duration_cast<microseconds>(end - start)) time_span = duration_cast<microseconds>(end - start);
global_clock[id] += time_span.count();
};
double get() {
system_clock::time_point end = system_clock::now();
decltype(duration_cast<microseconds>(end - start)) time_span = duration_cast<microseconds>(end - start);
return time_span.count() * 1.0 * microseconds::period::num / microseconds::period::den;
}
void print() {
system_clock::time_point end = system_clock::now();
decltype(duration_cast<microseconds>(end - start)) time_span = duration_cast<microseconds>(end - start);
DBGprint("duration: %f\n", time_span.count() * 1.0 * microseconds::period::num / microseconds::period::den);
}
};
class Util {
public:
static void int_to_char(char* &p, int u);
static void ll_to_char(char* &p, ll u);
static int char_to_int(char* &p);
static ll char_to_ll(char* &p);
static void int_to_header(char* p, int u);
static int header_to_int(char* p);
static int getNext(char *p, int begin);
static int getint(char* p,int &begin);
static ll getll(char* p,int &begin);
static int getfixpoint(char *p, int &begin);
static ll randomlong();
static ll128 get_residual(ll128 a);
static ll128 get_sign(ll128 a);
static ll128 get_abs(ll128 a);
static ll128 sqrt(ll128 a);
static ll128 inverse(ll128 a, ll128 b);
static ll128 power(ll128 a, ll128 b);
static ll128 cal_perm(ll128 key[], int l, int k);
};
};
std::ostream&
operator<<( std::ostream& dest, __int128_t value );
#endif //MPC_ML_CONSTANT_H