-
Notifications
You must be signed in to change notification settings - Fork 77
/
cxxmatrix.hpp
69 lines (59 loc) · 1.42 KB
/
cxxmatrix.hpp
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
#ifndef cxxmatrix_hpp
#define cxxmatrix_hpp
#include <cstdint>
#include <random>
#include <limits>
#include <string>
namespace cxxmatrix {
typedef uint8_t byte;
bool term_winsize_from_env(int& cols, int& rows);
void trapwinch(int sig);
void traptstp(int sig);
void trapcont(int sig);
}
namespace cxxmatrix::util {
inline std::mt19937& rand_engine() {
static std::random_device seed_gen;
static std::mt19937 engine(seed_gen());
return engine;
}
inline std::uint32_t rand() {
static std::uniform_int_distribution<std::uint32_t> dist(0, std::numeric_limits<std::uint32_t>::max());
return dist(rand_engine());
}
inline double randf() {
static std::uniform_real_distribution<double> dist(0, 1.0);
return dist(rand_engine());
}
inline char32_t rand_char() {
std::uint32_t r = util::rand() % 80;
if (r < 10)
return U'0' + r;
else
r -= 10;
if (r < 46)
return U'ー' + r;
else
r -= 46;
return U"<>*+.:=_|"[r % 9];
}
inline int mod(int value, int modulo) {
value %= modulo;
if (value < 0) value += modulo;
return value;
}
inline constexpr double interpolate(double value, double a, double b) {
return a + (b - a) * value;
}
inline std::vector<std::string_view> split(const char* text, char c) {
std::vector<std::string_view> vec;
char const* p = text;
do {
char const* s = p;
while (*p && *p != c) p++;
vec.emplace_back(s, p - s);
} while (*p++ == c);
return vec;
}
}
#endif