Skip to content

Commit 2f60bbf

Browse files
committed
Renamed Problem into StackAlgo
1 parent 86235d5 commit 2f60bbf

10 files changed

+91
-92
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ Makefile
3636
cmake_install.cmake
3737
install_manifest.txt
3838

39-
# Building directories + instances
39+
# Building directories + instances + results
4040
.gitignore
4141
.idea
4242
instances
43+
results
4344
debug/*
4445
minsizerel/*
4546
release/*

include/compare.hpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
Includes
66
==============================================================================*/
77
#include "data.hpp"
8-
#include "problem.hpp"
8+
#include "stackAlgo.hpp"
99

1010
/*==============================================================================
1111
Class : abstract, template (T context, D datas)
1212
Extensions :
1313
Aliases :
1414
Friends ->
15-
<- Problem
15+
<- StackAlgo
1616
==============================================================================*/
17-
template <class T, class D> class CompareStacks : public Problem<T, D> {
17+
template <class T, class D> class CompareStacks : public StackAlgo<T, D> {
1818
public:
1919
// Members functions
2020
CompareStacks<T, D>(std::string fileName);
@@ -24,7 +24,7 @@ template <class T, class D> class CompareStacks : public Problem<T, D> {
2424

2525
// IO
2626
void printCompare() {
27-
std::string str = Problem<T, D>::toString();
27+
std::string str = StackAlgo<T, D>::toString();
2828
str += "\n" + (*mNormalStack).toString();
2929
std::cout << str << std::endl;
3030
}
@@ -54,68 +54,68 @@ template <class T, class D> class CompareStacks : public Problem<T, D> {
5454

5555
template <class T, class D>
5656
CompareStacks<T, D>::CompareStacks(std::string fileName)
57-
: Problem<T, D>(fileName), mNormalStack(new NormalStack<T, D>()) {}
57+
: StackAlgo<T, D>(fileName), mNormalStack(new NormalStack<T, D>()) {}
5858

5959
/*==============================================================================
6060
Stack Functions: run, push, pop, top
6161
==============================================================================*/
6262
template <class T, class D> Data<T, D> CompareStacks<T, D>::popCompare() {
63-
return Problem<T, D>::mStack->pop(*this);
63+
return StackAlgo<T, D>::mStack->pop(*this);
6464
}
6565

6666
template <class T, class D> void CompareStacks<T, D>::runCompare(int buffer) {
6767
try {
68-
Problem<T, D>::initStackIntern();
69-
while ((Problem<T, D>::mInput.good())) {
70-
std::streampos position = Problem<T, D>::mInput.tellg();
71-
(*Problem<T, D>::mStack).setPosition(position);
68+
StackAlgo<T, D>::initStackIntern();
69+
while ((StackAlgo<T, D>::mInput.good())) {
70+
std::streampos position = StackAlgo<T, D>::mInput.tellg();
71+
(*StackAlgo<T, D>::mStack).setPosition(position);
7272
for (int i = 1; i <= buffer; i++) {
73-
bool bIndex = Problem<T, D>::top(i).mIndex == mNormalStack->top(i).mIndex;
74-
bool bData = Problem<T, D>::top(i).mData == mNormalStack->top(i).mData;
73+
bool bIndex = StackAlgo<T, D>::top(i).mIndex == mNormalStack->top(i).mIndex;
74+
bool bData = StackAlgo<T, D>::top(i).mData == mNormalStack->top(i).mData;
7575
if (!bIndex || !bData) {
76-
Problem<T, D>::println();
76+
StackAlgo<T, D>::println();
7777
std::cout << mNormalStack->toString() << std::endl;
7878
throw "The top $(i)st elements are different";
7979
}
8080
}
81-
std::vector<std::string> line = Problem<T, D>::readLine();
81+
std::vector<std::string> line = StackAlgo<T, D>::readLine();
8282
if ((line.front() == "-1") || (line.front() == "")) {
8383
break;
8484
}
8585
D data = readInput(line);
86-
Problem<T, D>::mIndex++;
87-
if ((*Problem<T, D>::mStack).empty() != mNormalStack->empty()) {
88-
(*Problem<T, D>::mStack).empty();
89-
Problem<T, D>::println();
86+
StackAlgo<T, D>::mIndex++;
87+
if ((*StackAlgo<T, D>::mStack).empty() != mNormalStack->empty()) {
88+
(*StackAlgo<T, D>::mStack).empty();
89+
StackAlgo<T, D>::println();
9090
std::cout << mNormalStack->toString() << std::endl;
91-
(*Problem<T, D>::mStack).empty();
91+
(*StackAlgo<T, D>::mStack).empty();
9292
throw "One stack is empty and not the other";
9393
}
94-
while ((!(Problem<T, D>::emptystack())) && (popCondition(data))) {
95-
Data<T, D> elt = Problem<T, D>::pop();
94+
while ((!(StackAlgo<T, D>::emptystack())) && (popCondition(data))) {
95+
Data<T, D> elt = StackAlgo<T, D>::pop();
9696
Data<T, D> eltNormal = mNormalStack->pop();
9797
popAction(elt);
9898
bool bIndex = elt.mIndex == eltNormal.mIndex;
9999
bool bData = elt.mData == eltNormal.mData;
100100
if (!bIndex || !bData) {
101-
Problem<T, D>::println();
102-
//std::cout << *Problem<T, D>::mContext << std::endl;
101+
StackAlgo<T, D>::println();
102+
//std::cout << *StackAlgo<T, D>::mContext << std::endl;
103103
std::cout << mNormalStack->toString() << std::endl;
104104
throw "The two elements popped are different";
105105
}
106106
}
107107
if (pushCondition(data)) {
108-
Data<T, D> elt(Problem<T, D>::mIndex, data);
108+
Data<T, D> elt(StackAlgo<T, D>::mIndex, data);
109109
pushAction(elt);
110-
Problem<T, D>::push(elt);
110+
StackAlgo<T, D>::push(elt);
111111
mNormalStack->push(elt);
112112
}
113-
if (Problem<T, D>::mStack->getBufferSize() > 0) {
113+
if (StackAlgo<T, D>::mStack->getBufferSize() > 0) {
114114
std::cout << "Is it working" << std::endl;
115-
for (int k = 1; k <= Problem<T, D>::mStack->getBufferSize(); k++) {
116-
if (Problem<T, D>::mStack->top(k).mIndex == mNormalStack->top(k).mIndex) {
117-
Problem<T, D>::println();
118-
//std::cout << *Problem<T, D>::mContext << std::endl;
115+
for (int k = 1; k <= StackAlgo<T, D>::mStack->getBufferSize(); k++) {
116+
if (StackAlgo<T, D>::mStack->top(k).mIndex == mNormalStack->top(k).mIndex) {
117+
StackAlgo<T, D>::println();
118+
//std::cout << *StackAlgo<T, D>::mContext << std::endl;
119119
std::cout << mNormalStack->toString() << std::endl;
120120
throw "The two elements at the k = $(k) position are different";
121121
}
@@ -129,14 +129,14 @@ template <class T, class D> void CompareStacks<T, D>::runCompare(int buffer) {
129129

130130
template <class T, class D> void CompareStacks<T, D>::readPush(int iter) {
131131
for (int i = 0; i < iter; i++) {
132-
std::streampos position = Problem<T, D>::mInput.tellg();
133-
Problem<T, D>::mStack->setPosition(position);
134-
std::vector<std::string> line = Problem<T, D>::readLine();
132+
std::streampos position = StackAlgo<T, D>::mInput.tellg();
133+
StackAlgo<T, D>::mStack->setPosition(position);
134+
std::vector<std::string> line = StackAlgo<T, D>::readLine();
135135
D data = readInput(line);
136-
Problem<T, D>::mIndex++;
137-
Data<T, D> elt(Problem<T, D>::mIndex, data);
136+
StackAlgo<T, D>::mIndex++;
137+
Data<T, D> elt(StackAlgo<T, D>::mIndex, data);
138138
pushAction(elt);
139-
Problem<T, D>::push(elt);
139+
StackAlgo<T, D>::push(elt);
140140
mNormalStack->push(elt);
141141
}
142142
}

include/compressedStack.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
Class : template (T context, D datas)
1919
Extensions :
2020
Aliases :
21-
Friends -> Problem
21+
Friends -> StackAlgo
2222
<- Signature, Component, Buffer, Data
2323
==============================================================================*/
24-
template <class T, class D> class Problem; // Required for the friendship
24+
template <class T, class D> class StackAlgo; // Required for the friendship
2525
template <class T, class D> class CompressedStack : public Stack<T, D> {
26-
friend class Problem<T, D>;
26+
friend class StackAlgo<T, D>;
2727

2828
public:
2929
CompressedStack<T, D>(int size, int space, int buffer,
@@ -44,7 +44,7 @@ template <class T, class D> class CompressedStack : public Stack<T, D> {
4444
// component = i > 0 tests component i
4545

4646
Data<T, D> top(int k = 1);
47-
Data<T, D> pop(Problem<T, D> &Problem);
47+
Data<T, D> pop(StackAlgo<T, D> &StackAlgo);
4848
void push(const Data<T, D> &data);
4949
void copyContent(CompressedStack<T, D> &stack);
5050
void compress();
@@ -84,11 +84,11 @@ template <class T, class D> class CompressedStack : public Stack<T, D> {
8484

8585
/* Pop related */
8686
void popBuffer();
87-
SPData<T, D> popExplicit(Problem<T, D> &Problem, int component);
87+
SPData<T, D> popExplicit(StackAlgo<T, D> &StackAlgo, int component);
8888
void popComponent(int index, int component);
8989
void propagate(int index, int lvl, int component = 1);
9090
void clear(int index, int lvl, int component);
91-
void reconstruct(Problem<T, D> &problem);
91+
void reconstruct(StackAlgo<T, D> &problem);
9292

9393
// Other getters
9494
SPData<T, D> getExplicitData(int k);
@@ -103,7 +103,7 @@ template <class T, class D> class CompressedStack : public Stack<T, D> {
103103
// Position of previous input (before reading)
104104
std::streampos mPosition;
105105

106-
// Pointer to the context in Problem
106+
// Pointer to the context in StackAlgo
107107
std::shared_ptr<T> mContext;
108108

109109
protected:
@@ -613,7 +613,7 @@ void CompressedStack<T, D>::compress(Block<T, D> block) {
613613
2) copyContent
614614
==============================================================================*/
615615
template <class T, class D>
616-
void CompressedStack<T, D>::reconstruct(Problem<T, D> &problem) {
616+
void CompressedStack<T, D>::reconstruct(StackAlgo<T, D> &problem) {
617617
std::shared_ptr<Signature<T, D>> sign;
618618
int lvl;
619619
for (lvl = mDepth; lvl >= 0; lvl--) {
@@ -690,7 +690,7 @@ void CompressedStack<T, D>::copyContent(CompressedStack<T, D> &stack) {
690690
6) propagate
691691
==============================================================================*/
692692
template <class T, class D>
693-
Data<T, D> CompressedStack<T, D>::pop(Problem<T, D> &problem) {
693+
Data<T, D> CompressedStack<T, D>::pop(StackAlgo<T, D> &problem) {
694694
popBuffer();
695695
if (empty(mDepth)) {
696696
reconstruct(problem);
@@ -712,7 +712,7 @@ template <class T, class D> void CompressedStack<T, D>::popBuffer() {
712712
}
713713

714714
template <class T, class D>
715-
SPData<T, D> CompressedStack<T, D>::popExplicit(Problem<T, D> &problem,
715+
SPData<T, D> CompressedStack<T, D>::popExplicit(StackAlgo<T, D> &problem,
716716
int component) {
717717
SPData<T, D> elt = topPointer(1);
718718
pop_back(mDepth, component);

include/convexHull.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "problem.hpp"
1+
#include "stackAlgo.hpp"
22
#include "compare.hpp"
33
#include "Point2D.hpp"
44

@@ -11,9 +11,9 @@ class emptyContext{};
1111
/*==============================================================================
1212
Instantiation of a problem
1313
==============================================================================*/
14-
class convexHull : public Problem<emptyContext, Point2D> {
14+
class convexHull : public StackAlgo<emptyContext, Point2D> {
1515
public:
16-
convexHull(std::string filePath) : Problem<emptyContext, Point2D>(filePath) {}
16+
convexHull(std::string filePath) : StackAlgo<emptyContext, Point2D>(filePath) {}
1717

1818
private:
1919
// Functions to run the stack

include/data.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
Class : template (D datas)
1414
Extensions :
1515
Aliases : Explicit, ExplicitPointer
16-
Friends -> Component, CompressedStack, Problem
16+
Friends -> Component, CompressedStack, StackAlgo
1717
<-
1818
==============================================================================*/
1919
template <class T, class D> class Component; // Required for the friendship
2020
template <class T, class D>
2121
class CompressedStack; // Required for the friendship
22-
template <class T, class D> class Problem; // Required for the friendship
22+
template <class T, class D> class StackAlgo; // Required for the friendship
2323
template <class T, class D> class CompareStacks; // Required for the friendship
2424
class Comparison; // Required for the friendship
2525
template <class T, class D> class Data {
2626
friend class Component<T, D>;
2727
friend class CompressedStack<T, D>;
28-
friend class Problem<T, D>;
28+
friend class StackAlgo<T, D>;
2929
friend class CompareStacks<T, D>;
3030
friend class Comparison;
3131

include/normalStack.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
Class : template (D datas)
1212
Extensions :
1313
Aliases :
14-
Friends -> Problem
14+
Friends -> StackAlgo
1515
<-
1616
==============================================================================*/
17-
template <class T, class D> class Problem; // Required for the friendship
17+
template <class T, class D> class StackAlgo; // Required for the friendship
1818
template <class T, class D> class CompareStacks; // Required for the friendship
1919
class Comparison; // Required for the friendship
2020
template <class T, class D> class NormalStack : public Stack<T, D> {
21-
friend class Problem<T, D>;
21+
friend class StackAlgo<T, D>;
2222
friend class CompareStacks<T, D>;
2323
friend class Comparison;
2424

@@ -33,7 +33,7 @@ template <class T, class D> class NormalStack : public Stack<T, D> {
3333
Explicit<T, D> mDatas; // vector of Data
3434

3535
// Stack common methods
36-
Data<T, D> pop(Problem<T, D> &problem);
36+
Data<T, D> pop(StackAlgo<T, D> &problem);
3737
Data<T, D> pop();
3838
void push(const Data<T, D> &data);
3939
Data<T, D> top(int k = 1);
@@ -73,7 +73,7 @@ bool NormalStack<T, D>::empty(int lvl, int component) {
7373
}
7474

7575
template <class T, class D>
76-
Data<T, D> NormalStack<T, D>::pop(Problem<T, D> &problem) {
76+
Data<T, D> NormalStack<T, D>::pop(StackAlgo<T, D> &problem) {
7777
Data<T, D> data = mDatas.back();
7878
mDatas.pop_back();
7979
return data;

include/stack.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ template <class T, class D> class Stack {
2222
virtual ~Stack<T, D>(){};
2323

2424
// Common stack functions
25-
virtual Data<T, D> pop(Problem<T, D> &problem) = 0;
25+
virtual Data<T, D> pop(StackAlgo<T, D> &problem) = 0;
2626
virtual void push(const Data<T, D> &data) = 0;
2727
virtual Data<T, D> top(int k = 1) = 0;
2828

0 commit comments

Comments
 (0)