-
Notifications
You must be signed in to change notification settings - Fork 1
/
vector.h
45 lines (37 loc) · 1004 Bytes
/
vector.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
#include <vector>
#include <algorithm>
#include <utility>
#include <memory>
typedef unsigned long long ui64;
struct Vector {
Vector(size_t n = 0, ui64 el = 0);
Vector(Vector const &other);
~Vector();
void resize(size_t n);
void push_back(ui64 x);
ui64 pop_back();
ui64& back();
void reverse();
bool empty();
size_t size() __attribute__((always_inline));
Vector& operator=(Vector const &vec);
ui64& operator[](const size_t k) __attribute__((always_inline));
ui64 operator[](const size_t k) const __attribute__((always_inline));
private:
union number{
std::vector<ui64> a;
ui64 small_a;
};
std::shared_ptr<number> num;
bool is_long;
size_t length;
};
inline size_t Vector::size() {
return length;
}
inline ui64& Vector::operator[](const size_t k) {
return (is_long ? num->a[k] : num->small_a);
}
inline ui64 Vector::operator[](const size_t k) const {
return (is_long ? num->a[k] : num->small_a);
}