-
Notifications
You must be signed in to change notification settings - Fork 1
/
ac_comm.h
62 lines (55 loc) · 1.65 KB
/
ac_comm.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
#pragma once
#include <stdint.h>
namespace ac {
enum { CASE_IGNORE = 1 };
enum { // 8 bits
// for STATE & FAKE_STATE
S_FAKE = 1,
S_FINAL = 2,
S_DOUBLE_FINAL = 4,
S_FINAL_ON_FAIL = 8,
};
struct mem_bound_t {
const uint8_t* data;
const uint8_t* tail;
};
size_t mem_bound_size(mem_bound_t& mb) {
return mb.tail - mb.data;
}
void mem_bound_init(mem_bound_t& mb, const char* str) {
mb.data = (uint8_t*)str;
mb.tail = mb.data + (str ? strlen(str) : 0);
}
void mem_bound_init(mem_bound_t & mb, const std::string & str) {
mb.data = (uint8_t*)str.c_str();
mb.tail = mb.data + str.size();
}
void mem_bound_init(mem_bound_t & mb, std::string && str) {
mb.data = (uint8_t*)str.c_str();
mb.tail = mb.data + str.size();
}
void mem_bound_init(mem_bound_t & mb, const void* ptr, size_t size) {
mb.data = (uint8_t*)ptr;
mb.tail = mb.data + size;
}
template < typename T>
struct final_mask {
static const size_t highest_bit = sizeof(T) * 8 - 1;
static const size_t mask = 1 << highest_bit;
static const size_t rest_mask = ((T)-1) >> 1;
};
struct BaseAcc {
template <typename K>
static inline void set_final(K& k) {
k |= final_mask<K>::mask;
}
template < typename K>
static inline bool is_final(const K& k) {
return !!(k & final_mask<K>::mask);
}
template < typename K>
static inline K get_value(const K& k) {
return k & final_mask<K>::rest_mask;
}
};
};