Skip to content

Commit 1c1469c

Browse files
committed
Corrected ConvexHull popCondition and pop with Buffer > 0
Updated StackAlgoExtras to pre/post actions. Buggy Corrected ConvexHull popCondition and pop with Buffer > 0 Erased debug printing
1 parent 01b5859 commit 1c1469c

File tree

8 files changed

+224
-135
lines changed

8 files changed

+224
-135
lines changed

examples/convexhull/convexHull32.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ int main(int argc, char *argv[]) {
2323
// Getting the path of the instance to test
2424
std::string filepath = argv[1];
2525

26-
std::cout<<" aaaa"<<std::endl;
27-
2826
ConvexHull32 stack(filepath);
2927
stack.run();
30-
// stack.println();
28+
// stack.println();
3129

3230
return 0;
3331
}

examples/convexhull/include/convexHull.hpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
#include "../../../include/stackAlgo.hpp"
99
#include "point2D.hpp"
1010

11-
12-
double pops=0;
13-
double total=0;
11+
double pops = 0;
12+
double total = 0;
1413

1514
/*==============================================================================
1615
Empty type for the context (empty for the Convex Hull problem)
@@ -65,7 +64,7 @@ Point2D ConvexHull<I>::readInput(std::vector<std::string> line) {
6564

6665
Point2D p(x, y);
6766

68-
//std::cout << "I JUST READ " << p << std::endl;
67+
// std::cout << "I JUST READ " << p << std::endl;
6968
return p;
7069
}
7170

@@ -74,8 +73,7 @@ template <class I> std::shared_ptr<emptyContext> ConvexHull<I>::initStack() {
7473
std::cout << "going to read two values " << std::endl;
7574

7675
// first, read and push two values
77-
StackAlgo<emptyContext, Point2D, I>::readPush(1);
78-
StackAlgo<emptyContext, Point2D, I>::readPush(1);
76+
StackAlgo<emptyContext, Point2D, I>::readPush(2);
7977

8078
std::cout << "done reading two values " << std::endl;
8179

@@ -86,31 +84,40 @@ template <class I> std::shared_ptr<emptyContext> ConvexHull<I>::initStack() {
8684

8785
template <class I> bool ConvexHull<I>::popCondition(Point2D last) {
8886
Point2D minus1, minus2;
89-
total++;
90-
std::cout << last << " <<<< pop condition enter " << std::endl;
87+
total++;
88+
std::cout << std::endl << last << " <<<< pop condition enter " << std::endl;
9189
StackAlgo<emptyContext, Point2D, I>::println();
9290

9391
// read the two previous elements
9492
minus1 = StackAlgo<emptyContext, Point2D, I>::top(1).getData();
93+
if (StackAlgo<emptyContext, Point2D, I>::mStack->getBufferLength() < 2) {
94+
return true;
95+
}
96+
9597
minus2 = StackAlgo<emptyContext, Point2D, I>::top(2).getData();
9698

97-
std::cout << last << " <<<< pop condition read two before " << minus2<< minus1 << std::endl;
99+
std::cout << last << " <<<< pop condition read two before " << minus2
100+
<< minus1 << std::endl;
98101

99102
if (Point2D::orientation(minus2, minus1, last) == 1) {
100103
pops++;
101-
std::cout << last << " <<<< pop condition returning true "<<pops/total<<" tot "<<total << std::endl;
104+
std::cout << last
105+
<< " <<<< "
106+
" pop condition returning true "
107+
<< pops / total << " tot " << total << std::endl;
102108

103109
return true;
104110
}
105-
std::cout << last << " <<<< pop condition returning false "<<pops/total<<" tot "<<total << std::endl;
106-
111+
std::cout << last << " "
112+
" <<<< pop condition returning false "
113+
<< pops / total << " tot " << total << std::endl;
107114

108115
return false;
109116
}
110117
template <class I> void ConvexHull<I>::prePop(Point2D data) {}
111118
template <class I>
112119
void ConvexHull<I>::postPop(Point2D data, Data<emptyContext, Point2D, I> elt) {
113-
std::cout << elt.getData() << " <<<< Pop!" << std::endl;
120+
std::cout << elt.getData() << " <<<< (post-)Pop!" << std::endl;
114121
}
115122
template <class I> void ConvexHull<I>::noPop(Point2D data) {}
116123

@@ -122,7 +129,8 @@ template <class I>
122129
void ConvexHull<I>::prePush(Data<emptyContext, Point2D, I> elt) {}
123130
template <class I>
124131
void ConvexHull<I>::postPush(Data<emptyContext, Point2D, I> elt) {
125-
std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here " << elt.getData() << std::endl;
132+
std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here "
133+
<< elt.getData() << std::endl;
126134
}
127135
template <class I> void ConvexHull<I>::noPush(Point2D data) {}
128136

examples/convexhull/include/convexHullExtras.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ std::shared_ptr<emptyContext> ConvexHullExtras<I>::initStack() {
7575
// first, read and push two values
7676
StackAlgoExtras<emptyContext, Point2D, I>::readPushCompare();
7777
StackAlgoExtras<emptyContext, Point2D, I>::readPushCompare();
78+
StackAlgoExtras<emptyContext, Point2D, I>::readPushCompare();
7879

7980
// StackAlgoExtras<emptyContext, Point2D, I>::printCompare();
8081

@@ -86,22 +87,19 @@ std::shared_ptr<emptyContext> ConvexHullExtras<I>::initStack() {
8687

8788
template <class I> bool ConvexHullExtras<I>::popCondition(Point2D last) {
8889
Point2D minus1, minus2;
89-
90-
// std::cout << last << " <<<< pop condition enter " << std::endl;
90+
std::cout << std::endl << last << " <<<< pop condition enter " << std::endl;
91+
StackAlgo<emptyContext, Point2D, I>::println();
9192

9293
// read the two previous elements
93-
minus1 = StackAlgoExtras<emptyContext, Point2D, I>::top(1).getData();
94-
minus2 = StackAlgoExtras<emptyContext, Point2D, I>::top(2).getData();
95-
96-
// std::cout << last << " <<<< pop condition read two before " << minus1<<
97-
// minus2 << std::endl;
98-
99-
if (Point2D::orientation(minus2, minus1, last) == 2) {
100-
// std::cout << last << " <<<< pop condition returning true " << std::endl;
94+
minus1 = StackAlgo<emptyContext, Point2D, I>::top(1).getData();
95+
if (StackAlgo<emptyContext, Point2D, I>::mStack->getBufferLength() < 2) {
96+
return true;
97+
}
10198

99+
minus2 = StackAlgo<emptyContext, Point2D, I>::top(2).getData();
100+
if (Point2D::orientation(minus2, minus1, last) == 1) {
102101
return true;
103102
}
104-
// std::cout << last << " <<<< pop condition returning false " << std::endl;
105103

106104
return false;
107105
}

extras/classicStack.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ClassicStack : public Stack<T, D, I> {
5050
ExplicitPointer<T, D, I> getFirstExplicit();
5151
Block<T, D, I> getFirstBlock();
5252
I getBufferSize();
53+
I getBufferLength();
5354
};
5455

5556
/*==============================================================================
@@ -116,6 +117,10 @@ ExplicitPointer<T, D, I> ClassicStack<T, D, I>::getFirstExplicit() {
116117
template <class T, class D, class I> I ClassicStack<T, D, I>::getBufferSize() {
117118
return 0;
118119
}
120+
template <class T, class D, class I>
121+
I ClassicStack<T, D, I>::getBufferLength() {
122+
return getBufferSize();
123+
}
119124

120125
template <class T, class D, class I>
121126
Block<T, D, I> ClassicStack<T, D, I>::getFirstBlock() {

0 commit comments

Comments
 (0)