-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptvector.h
More file actions
63 lines (40 loc) · 1.07 KB
/
optvector.h
File metadata and controls
63 lines (40 loc) · 1.07 KB
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
#ifndef BIGINT_OPTVECTOR_H
#define BIGINT_OPTVECTOR_H
#include <vector>
#include <cstddef>
#include <memory>
struct shared_data {
std::shared_ptr<std::vector<uint32_t>> value;
shared_data();
shared_data(shared_data const &other);
void make_own();
};
struct optvector {
optvector();
~optvector();
optvector(optvector const &other);
uint32_t &back();
uint32_t back() const;
void resize(size_t i);
void resize(size_t i, uint32_t val);
size_t size() const;
uint32_t &operator[](size_t i);
uint32_t operator[](size_t i) const;
optvector &operator=(optvector const &other);
uint32_t pop_back();
void push_back(uint32_t val);
void swap(optvector &b);
private:
union {
uint32_t small_value;
shared_data *data;
};
char contains_small; //helps to see whether we have small_value or not
bool is_small() const {
return bool(this->contains_small & 1);
}
bool small_size() const {
return bool((this->contains_small & 2) >> 1);
}
};
#endif //BIGINT_OPTVECTOR_H