add subject and main from 42
This commit is contained in:
43
.gitignore
vendored
43
.gitignore
vendored
@@ -1,41 +1,16 @@
|
|||||||
# These are some examples of commonly ignored file patterns.
|
# default bitbucket gitignore
|
||||||
# You should customize this list as applicable to your project.
|
|
||||||
# Learn more about .gitignore:
|
|
||||||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
|
|
||||||
|
|
||||||
# Node artifact files
|
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
# Compiled Java class files
|
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
# Compiled Python bytecode
|
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
||||||
# Log files
|
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# Package files
|
|
||||||
*.jar
|
*.jar
|
||||||
|
|
||||||
# Maven
|
|
||||||
target/
|
target/
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
# JetBrains IDE
|
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Unit test reports
|
|
||||||
TEST*.xml
|
TEST*.xml
|
||||||
|
|
||||||
# Generated by MacOS
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# Generated by Windows
|
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Applications
|
|
||||||
*.app
|
*.app
|
||||||
*.exe
|
*.exe
|
||||||
*.war
|
*.war
|
||||||
@@ -48,3 +23,19 @@ Thumbs.db
|
|||||||
*.mov
|
*.mov
|
||||||
*.wmv
|
*.wmv
|
||||||
|
|
||||||
|
# 42
|
||||||
|
*.o
|
||||||
|
*.swp
|
||||||
|
*.out
|
||||||
|
*.stackdump
|
||||||
|
*.a
|
||||||
|
*.so
|
||||||
|
*.dSYM
|
||||||
|
.vscode
|
||||||
|
*.lnk
|
||||||
|
*.zip
|
||||||
|
*.pdf
|
||||||
|
/builds
|
||||||
|
|
||||||
|
# cube3d
|
||||||
|
containers
|
||||||
|
|||||||
116
main.cpp
Normal file
116
main.cpp
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <deque>
|
||||||
|
#if 1 //CREATE A REAL STL EXAMPLE
|
||||||
|
#include <map>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
namespace ft = std;
|
||||||
|
#else
|
||||||
|
#include <map.hpp>
|
||||||
|
#include <stack.hpp>
|
||||||
|
#include <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 < 10000; i++)
|
||||||
|
{
|
||||||
|
int access = rand();
|
||||||
|
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;
|
||||||
|
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 << *it;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user