-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
130 lines (115 loc) · 3.32 KB
/
main.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbari <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/17 15:58:35 by mbari #+# #+# */
/* Updated: 2022/03/22 23:21:45 by mbari ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <string>
#include <deque>
#if 0 //CREATE A REAL STL EXAMPLE
#include <map>
#include <stack>
#include <vector>
namespace ft = std;
#else
#include "containers/map/map.hpp"
#include "containers/stack/stack.hpp"
#include "containers/vector/vector.hpp"
#endif
#include <stdlib.h>
#define MAX_RAM 4294967296
#define BUFFER_SIZE 4096
struct Buffer
{
int idx;
char buff[BUFFER_SIZE];
};
#define COUNT (MAX_RAM / (int)sizeof(Buffer))
template<typename T>
class MutantStack : public ft::stack<T>
{
public:
MutantStack() {}
MutantStack(const MutantStack<T>& src) { *this = src; }
MutantStack<T>& operator=(const MutantStack<T>& rhs)
{
this->c = rhs.c;
return *this;
}
~MutantStack() {}
typedef typename ft::stack<T>::container_type::iterator iterator;
iterator begin() { return this->c.begin(); }
iterator end() { return this->c.end(); }
};
int main(int argc, char** argv)
{
if (argc != 2)
{
std::cerr << "Usage: ./test seed" << std::endl;
std::cerr << "Provide a seed please" << std::endl;
std::cerr << "Count value:" << COUNT << std::endl;
return 1;
}
const int seed = atoi(argv[1]);
srand(seed);
ft::vector<std::string> vector_str;
ft::vector<int> vector_int;
ft::stack<int> stack_int;
ft::vector<Buffer> vector_buffer;
ft::stack<Buffer, std::deque<Buffer> > stack_deq_buffer;
ft::map<int, int> map_int;
for (int i = 0; i < COUNT; i++)
{
vector_buffer.push_back(Buffer());
}
for (int i = 0; i < COUNT; i++)
{
const int idx = rand() % COUNT;
vector_buffer[idx].idx = 5;
}
ft::vector<Buffer>().swap(vector_buffer);
try
{
for (int i = 0; i < COUNT; i++)
{
const int idx = rand() % COUNT;
vector_buffer.at(idx);
std::cerr << "Error: THIS VECTOR SHOULD BE EMPTY!!" <<std::endl;
}
}
catch(const std::exception& e)
{
//NORMAL ! :P
}
for (int i = 0; i < COUNT; ++i)
{
map_int.insert(ft::make_pair(rand(), rand()));
}
int sum = 0;
for (int i = 0; i < 100; i++)
{
int access = rand();
// std::cout << i << " -> " << access << std::endl;
sum += map_int[access];
}
std::cout << "should be constant with the same seed: " << sum << std::endl;
{
// ft::map<int, int> copy = map_int;
}
MutantStack<char> iterable_stack;
// std::cout << "done";
for (char letter = 'a'; letter <= 'z'; letter++)
iterable_stack.push(letter);
for (MutantStack<char>::iterator it = iterable_stack.begin(); it != iterable_stack.end(); it++)
{
// std::cout << "done";
std::cout << *it;
}
return (0);
}