-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_vector.h
More file actions
73 lines (44 loc) · 1.24 KB
/
my_vector.h
File metadata and controls
73 lines (44 loc) · 1.24 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
64
65
66
67
68
69
70
71
72
73
//
// Created by Artem Ustinov on 07.06.18.
//
#ifndef BIG_INTEGER_MY_VECTOR_H
#define BIG_INTEGER_MY_VECTOR_H
#include <cstdint>
#include <cstddef>
#include <memory>
class my_vector {
public:
void swap(my_vector &other);
uint32_t &operator[](size_t const &_n);
const uint32_t &operator[](size_t const &_n) const;
void push_back(uint32_t _a);
size_t size() const;
my_vector();
my_vector(my_vector const &other);
explicit my_vector(size_t s);
my_vector(size_t s, uint32_t _n);
my_vector &operator=(my_vector const &other);
void assign(size_t _n, uint32_t _a);
void resize(size_t _n);
void resize(size_t _n, uint32_t _a);
uint32_t back();
size_t capacity() const;
~my_vector();
private:
void ensure_capacity(size_t _n);
static const uint32_t _SIZE = 4;
size_t _size;
struct dynamic_data {
std::shared_ptr<uint32_t[]> data;
size_t capacity;
dynamic_data() = default;
dynamic_data(dynamic_data const &other) = default;
dynamic_data(uint32_t other[], size_t c) : data(other), capacity(c) {}
};
union {
dynamic_data big;
uint32_t small[_SIZE];
};
bool is_small;
};
#endif //BIG_INTEGER_MY_VECTOR_H