| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#pragma once |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#include |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
namespace panda { |
|
6
|
|
|
|
|
|
|
|
|
7
|
52003
|
|
|
|
|
|
inline string varint_encode(uint32_t i) { |
|
8
|
52003
|
|
|
|
|
|
string res; |
|
9
|
154446
|
100
|
|
|
|
|
while (i > 127) { |
|
10
|
102443
|
50
|
|
|
|
|
res += 0x80 | uint8_t(i & 0x7F); |
|
11
|
102443
|
|
|
|
|
|
i >>= 7; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
52003
|
50
|
|
|
|
|
res += uint8_t(i); |
|
14
|
52003
|
|
|
|
|
|
return res; |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
52019
|
|
|
|
|
|
inline uint32_t varint_decode(const string& str) { |
|
18
|
52019
|
|
|
|
|
|
size_t i = 0; |
|
19
|
52019
|
|
|
|
|
|
uint32_t r = 0; |
|
20
|
154462
|
50
|
|
|
|
|
while (i < str.size() && (str[i] & 0x80)) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
21
|
102443
|
|
|
|
|
|
r |= (str[i] & 0x7f) << 7*i; |
|
22
|
102443
|
|
|
|
|
|
++i; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
52019
|
|
|
|
|
|
r |= (str[i] & 0x7f) << 7*i; |
|
25
|
52019
|
|
|
|
|
|
return r; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
34500
|
|
|
|
|
|
inline string varint_encode_s(int32_t i) { |
|
29
|
|
|
|
|
|
|
//ZigZag encoding, x86 (both 32,64) only, uses signed bit shift |
|
30
|
34500
|
|
|
|
|
|
return varint_encode((i << 1) ^ (i >> 31)); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
34516
|
|
|
|
|
|
inline int32_t varint_decode_s(const string& str) { |
|
34
|
|
|
|
|
|
|
//ZigZag decoding |
|
35
|
34516
|
|
|
|
|
|
uint32_t i = varint_decode(str); |
|
36
|
34516
|
|
|
|
|
|
return ((i >> 1) ^ -(i & 1)); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
|
struct VarIntStack { |
|
40
|
|
|
|
|
|
|
string storage; |
|
41
|
|
|
|
|
|
|
|
|
42
|
28
|
|
|
|
|
|
VarIntStack() = default; |
|
43
|
14
|
|
|
|
|
|
VarIntStack(const VarIntStack&) = default; |
|
44
|
10
|
|
|
|
|
|
VarIntStack(VarIntStack&&) = default; |
|
45
|
52
|
|
|
|
|
|
~VarIntStack() = default; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
VarIntStack& operator=(const VarIntStack&) = default; |
|
48
|
|
|
|
|
|
|
VarIntStack& operator=(VarIntStack&&) = default; |
|
49
|
|
|
|
|
|
|
|
|
50
|
17
|
|
|
|
|
|
void push(int32_t val) { |
|
51
|
17
|
50
|
|
|
|
|
storage = varint_encode_s(val) + storage; |
|
|
|
50
|
|
|
|
|
|
|
52
|
17
|
|
|
|
|
|
} |
|
53
|
6
|
|
|
|
|
|
void pop() { |
|
54
|
6
|
|
|
|
|
|
storage.offset(size_of_first()); |
|
55
|
6
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
33
|
|
|
|
|
|
int32_t top() const { |
|
58
|
33
|
50
|
|
|
|
|
return varint_decode_s(storage.substr(0, size_of_first())); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
12
|
|
|
|
|
|
size_t size() const { |
|
61
|
12
|
|
|
|
|
|
size_t res = 0; |
|
62
|
30
|
100
|
|
|
|
|
for (char c : storage) { |
|
63
|
18
|
50
|
|
|
|
|
if (!(c&0x80)) { |
|
64
|
18
|
|
|
|
|
|
res += 1; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
12
|
|
|
|
|
|
return res; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
bool empty() const { |
|
71
|
|
|
|
|
|
|
return storage.empty(); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
private: |
|
75
|
39
|
|
|
|
|
|
size_t size_of_first() const { |
|
76
|
39
|
|
|
|
|
|
size_t pos = 0; |
|
77
|
42
|
50
|
|
|
|
|
for (; pos < storage.size(); ++pos) { |
|
78
|
42
|
100
|
|
|
|
|
if (!(storage[pos] & 0x80)) { |
|
79
|
39
|
|
|
|
|
|
break; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
39
|
|
|
|
|
|
return pos + 1; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
}; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |