-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathheap.hpp
60 lines (50 loc) · 1.33 KB
/
heap.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
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
class BigInt {
public:
vector<char> digit;
};
const ll NOT_HEAP = 0;
template <typename T>
class Heap {
public:
vector<vector<T>> heap_data;
T read(ll i, ll j, TokenPosition position, stack<CallStack>& callstack) {
if (i <= 0 || j <= 0) ErrorCode(HEAP_OUT_OF_INDEX, position, callstack);
if (i <= heap_data.size() && j <= heap_data[i - 1].size())
return heap_data[i - 1][j - 1];
ErrorCode(HEAP_OUT_OF_INDEX, position, callstack);
}
bool canRead(ll i, ll j) {
if (i <= 0 || j <= 0)
return false;
if (i <= heap_data.size() && j <= heap_data[i - 1].size())
return true;
return false;
}
T& write(ll i, ll j, TokenPosition position, stack<CallStack>& callstack) {
if (i <= 0 || j <= 0) ErrorCode(HEAP_OUT_OF_INDEX, position, callstack);
while (heap_data.size() < i) heap_data.push_back({});
while (heap_data[i - 1].size() < j) heap_data[i - 1].push_back(0);
return heap_data[i - 1][j - 1];
}
ll data_size(ll i, ll j) {
stack<CallStack> callstack;
ll cnt = 0;
while (canRead(i, j) && read(i, j, { -1, -1 }, callstack) != 0) {
cnt++, j++;
}
return cnt;
}
};
class Pointer {
public:
ll type = NOT_HEAP;
pair<ll, ll> position;
Pointer(ll type, ll i_var, ll j_var) {
this->type = type;
position = { i_var, j_var };
}
Pointer() {};
};