Skip to content

Commit d2608ee

Browse files
committed
Code save for 3 weeks travel
1 parent 9df37ba commit d2608ee

File tree

8 files changed

+99
-37
lines changed

8 files changed

+99
-37
lines changed

build/smartstack

164 KB
Binary file not shown.

include/component.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ template <class T, class D>
1111
class Component
1212
{
1313
public:
14-
Component<T,D>();
1514
Component<T,D>(int space, int depth);
1615

1716
// Setters
@@ -30,12 +29,6 @@ class Component
3029
};
3130

3231
/** Constructors **/
33-
template <class T, class D>
34-
Component<T,D>::Component()
35-
{
36-
std::cout << "Using default constructor for Component" << std::endl;
37-
}
38-
3932
template <class T, class D>
4033
Component<T,D>::Component(int space, int depth)
4134
{

include/compressedStack.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/* Compressed Stack itself */
1212
template <class T, class D>
13-
class CompressedStack:Stack<D>
13+
class CompressedStack: public Stack<D>
1414
{
1515
public:
1616
CompressedStack<T,D>(int size, int space);
@@ -43,16 +43,16 @@ class CompressedStack:Stack<D>
4343
/** Constructors **/
4444
template <class T, class D>
4545
CompressedStack<T,D>::CompressedStack(int size, int space)
46+
: mFirst(size,space)
47+
, mSecond(size,space)
4648
{
47-
mSize = size;
48-
mSpace = space;
49-
mDepth = (int) ceil(log(size)/log(space)-.1); // - 1;
49+
mSize = size;
50+
mSpace = space;
51+
mDepth = (int) ceil(log(size)/log(space)-.1); // - 1;
5052

51-
mPosition = 0;
53+
mPosition = 0;
5254

53-
mFirst = Component<T,D>(mSpace, mDepth);
54-
mSecond = Component<T,D>(mSpace, mDepth);
55-
mCompressed = initBlock<T>(mSpace);
55+
mCompressed = initBlock<T>(mSpace);
5656
}
5757

5858
/** IO **/
@@ -95,13 +95,15 @@ void CompressedStack<T,D>::push(Data<D> data)
9595
template <class T, class D>
9696
Data<D> CompressedStack<T,D>::pop()
9797
{
98-
98+
Data<D> d (1,1);
99+
return d;
99100
}
100101

101102
template <class T, class D>
102103
Data<D> CompressedStack<T,D>::top(int k)
103104
{
104-
105+
Data<D> d (1,1);
106+
return d;
105107
}
106108

107109
#endif /* COMPRESSEDSTACK */

include/normalStack.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "stack.hpp"
66

77
template <class D>
8-
class NormalStack:Stack<D>
8+
class NormalStack: public Stack<D>
99
{
1010
public:
1111
// Constructors

include/problem.hpp

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
/**** Problem : declaration ****/
55
#include "stack.hpp"
6+
#include "compressedStack.hpp"
7+
#include "normalStack.hpp"
68
#include <stdbool.h>
79
#include <fstream>
810
#include <string>
@@ -11,15 +13,24 @@ template <class T, class D>
1113
class Problem
1214
{
1315
public:
14-
Problem<T,D>(std::string fileName);
16+
// Problem<T,D>(std::string fileName);
17+
Problem<T,D>(std::string fileName, int size);
18+
Problem<T,D>(std::string fileName, int size, int space);
1519

16-
// Functions of the problem
17-
//void init();
18-
//D read();
20+
// Running the stack
21+
void run();
22+
23+
// Setters
24+
void setInitStack(void (*functionPointer)());
25+
void setReadInput(D (*functionPointer)());
26+
void setPopCondition(bool (*functionPointer)());
27+
void setPopAction(void (*functionPointer)());
28+
void setPushCondition(bool (*functionPointer)());
29+
void setPushAction(void (*functionPointer)());
1930

2031
private:
2132
// Input/Ouput
22-
std::ifstream mInput;
33+
std::ifstream* mInput;
2334
std::ofstream* mOutput; // output file is optional
2435

2536
// Stack Functions: defined by user
@@ -35,7 +46,64 @@ class Problem
3546
int mIndex;
3647

3748
// Stack: Normal or Compressed
38-
Stack<D> mStack;
49+
Stack<D>* mStack;
3950
};
4051

52+
/** Constructors **/
53+
template <class T, class D>
54+
Problem<T,D>::Problem(std::string fileName, int size)
55+
{
56+
std::ifstream ifstr;
57+
ifstr.open(fileName, std::ifstream::in);
58+
mInput = &ifstr;
59+
mOutput = nullptr;
60+
61+
mInitStack = nullptr;
62+
mReadInput = nullptr;
63+
mPopCondition = nullptr;
64+
mPopAction = nullptr;
65+
mPushCondition = nullptr;
66+
mPushAction = nullptr;
67+
68+
mContext = nullptr;
69+
mIndex = 0;
70+
71+
mStack = new NormalStack<T> (size);
72+
}
73+
74+
template <class T, class D>
75+
Problem<T,D>::Problem(std::string fileName, int size, int space)
76+
{
77+
std::ifstream ifstr;
78+
ifstr.open(fileName, std::ifstream::in);
79+
mInput = ifstr;
80+
mOutput = nullptr;
81+
82+
mInitStack = nullptr;
83+
mReadInput = nullptr;
84+
mPopCondition = nullptr;
85+
mPopAction = nullptr;
86+
mPushCondition = nullptr;
87+
mPushAction = nullptr;
88+
89+
mContext = nullptr;
90+
mIndex = 0;
91+
92+
mStack = new CompressedStack<T,D> (size, space);
93+
}
94+
95+
/** Running the stack **/
96+
template <class T, class D>
97+
void Problem<T,D>::run() {
98+
while (true) {
99+
D elt = mInput();
100+
while (true && mPopConditon(elt)) {
101+
(*mStack).pop();
102+
}
103+
if (mPushCondition()) {
104+
(*mStack).push(elt);
105+
}
106+
}
107+
}
108+
41109
#endif /* PROBLEM */

instances/test.csv

Whitespace-only changes.

src/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "../include/data.hpp"
44
#include "../include/normalStack.hpp"
55
#include "../include/compressedStack.hpp"
6+
#include "../include/problem.hpp"
7+
#include <string>
68

79
// Test Signature
810
void testSign()
@@ -52,7 +54,16 @@ void testCompressedStack()
5254
Block<int> block = initBlock<int>(5);
5355
Levels<int> lvls = initLevels<int>(3, 3);
5456
Component<int, int> comp(3,5);
55-
CompressedStack<int, int> stack = CompressedStack<int, int>(81,3);
57+
CompressedStack<int, int> stack (81,3);
58+
}
59+
60+
// Test problem
61+
void testProblem()
62+
{
63+
std::string filePath = "../instances/test.csv";
64+
Problem<int, int> problem (filePath, 5);
65+
66+
5667
}
5768

5869
// Main

src/problem.cpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)