Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 136cc67

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 Update README for v1.0 and wiki creation Update README and CMakeLists for v1.0 and wiki creation Corrected typo in README.md Update README.md
1 parent 01b5859 commit 136cc67

File tree

10 files changed

+302
-244
lines changed

10 files changed

+302
-244
lines changed

‎CMakeLists.txt‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
## Please modify this file freely to adapt to the production of other
22
## executables than convexhull and testrun
33

4+
# Description of the different builds
5+
# +---------------+--------------+--------------+----------|
6+
# | | optimization | assert works | stripped |
7+
# +---------------+--------------+--------------+----------|
8+
# | Debug | no | yes | no |
9+
# | Release | full | no | yes |
10+
# | RelWithDebInfo| good | no | no |
11+
# | MinSizeRel | size | no | yes |
12+
# +---------------+--------------+--------------+----------|
13+
14+
# Alias for cmake commands
15+
# alias cmakedebug='cmake 1ドル -DCMAKE_BUILD_TYPE=DEBUG'
16+
# alias cmakerelease='cmake 1ドル -DCMAKE_BUILD_TYPE=RELEASE'
17+
# alias cmakerelwithdebinfo='cmake 1ドル -DCMAKE_BUILD_TYPE=RELWITHDEBINFO'
18+
# alias cmakeminsizerel='cmake 1ドル -DCMAKE_BUILD_TYPE=MINSIZEREL'
19+
20+
# Example for release (first line only if the directory doesn't exist)
21+
# mkdir build_directory
22+
# cd build_directory
23+
# cmakerelease ..
24+
425
# Recent version of CMake required
526
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
627

7-
# Project Name
28+
# Project Name (change it freely)
829
project(smartstack)
930

1031
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
@@ -40,13 +61,12 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
4061
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
4162

4263
# Basic options for all builds
43-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Weffc++ -Wshadow -ansi")
4464
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wshadow")
4565
# Might need to be fixed for retrocompatibility or temporary
4666
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++0x-compat -Wno-unused")
4767

4868

49-
# Test directories
69+
# Include directories
5070
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
5171
message("inc_dirs = ${inc_dirs}")
5272

@@ -78,25 +98,3 @@ file(GLOB SOURCES "examples/testrun/testrunExtras.cpp")
7898
add_executable(testrunextras ${SOURCES})
7999
file(GLOB SOURCES "examples/testrun/generateInputTestRun.cpp")
80100
add_executable(generateInputTestRun ${SOURCES})
81-
82-
83-
# Description of the different builds
84-
# +---------------+--------------+--------------+----------|
85-
# | | optimization | assert works | stripped |
86-
# +---------------+--------------+--------------+----------|
87-
# | Debug | no | yes | no |
88-
# | Release | full | no | yes |
89-
# | RelWithDebInfo| good | no | no |
90-
# | MinSizeRel | size | no | yes |
91-
# +---------------+--------------+--------------+----------|
92-
93-
# Alias for cmake commands
94-
# alias cmakedebug='cmake 1ドル -DCMAKE_BUILD_TYPE=DEBUG'
95-
# alias cmakerelease='cmake 1ドル -DCMAKE_BUILD_TYPE=RELEASE'
96-
# alias cmakerelwithdebinfo='cmake 1ドル -DCMAKE_BUILD_TYPE=RELWITHDEBINFO'
97-
# alias cmakeminsizerel='cmake 1ドル -DCMAKE_BUILD_TYPE=MINSIZEREL'
98-
99-
# Example for debug (first line only if the directory doesn't exist)
100-
# mkdir build_directory
101-
# cd build_directory
102-
# cmakedebug ..

‎README.md‎

Lines changed: 55 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,118 +2,89 @@
22

33
The CompressedStacks.cpp module/library implements the compressed stack structure. This data structure behaves like a usual stack with the usual push and pop operations, but has the additional advantage that it uses less memory. Intuitively, when large blocks of information are pushed into the stack it *compresses* the bottom part (only stores partial information). This information is recomputed whenever it is needed afterwards. See the paper of [Barba *et al.*](https://arxiv.org/abs/1208.3663) for more details on this structure.
44

5+
Please consult the [wiki](https://github.com/Azzaare/CompressedStacks.cpp/wiki) of this project for further details such as : speed and memory consumption tests, more details about installation, examples, and more.
56

6-
<!-- TODO: Write down a better description -->
7-
8-
## Category of algorithms
7+
## Description of Stack Algorithms
98
<p>
10-
This compressed stack structure works correctly as a normal stack for any problems that read input from a file (**Is this true?**)). However, the running time is optimal when the input would be read sequentially with a classical stack structure. For this reason, the only function implemented in the Problem template to solve it (to do a run) is the one presented below in a simplified version.
9+
This compressed stack structure works correctly as a normal stack for any algorithm that read input from a file in a deterministic way. However, the running time is optimal when the input would be read sequentially with a classical stack structure. For this reason, the only function implemented in the StackAlgo template to solve it (to do a run) is the one presented below in a simplified version.
1110
</p>
1211

1312
```cpp
14-
template <class T, class D> void Problem<T, D>::run() {
13+
template <class T, class D> void StackAlgo<T, D>::run() {
1514
initStack();
1615
while (notEndOfFile()) {
1716
D data = readInput(line);
18-
while (notEmptystack() && popCondition(data)) {
19-
elt = pop();
20-
popAction(elt);
17+
while (notEmptystack()) {
18+
if (popCondition(data)) {
19+
prePop(data);
20+
elt = pop();
21+
postPop(elt,data);
22+
} else {
23+
noPop(data);
24+
}
2125
}
2226
if (pushCondition(data)) {
23-
pushAction(data);
27+
prePush(data);
2428
push(data);
29+
postPush(data);
30+
} else {
31+
noPush(data);
2532
}
2633
}
34+
reportStack();
2735
}
2836
```
37+
## Use case
38+
Concrete examples such as a basic test run and the convex hull problem can be found in the [wiki](https://github.com/Azzaare/CompressedStacks.cpp/wiki).
2939
30-
## Characterization of a problem
31-
<p>In the following examples, implementations of the Problem interface are given.</p>
32-
33-
### General example : ```Instance<T,D>```
40+
### Abstract example : ```Instance<T,D,I>```
41+
<p>An instance of a Stack Algorithm is described by a set of templates parameters T, D, and I and a set of methods used in the run function above.</p>
3442
3543
```cpp
36-
#include <string>
37-
#include <vector>
38-
#include <memory>
44+
// T is the type of the context, D is the type of the input data and I is the type of your integer indexes.
3945
40-
// T is the type of the context and D is the type of the input data.
41-
class Instance: public Problem<T,D>{
46+
class Instance: public StackAlgo<T,D,I>{
4247
public:
43-
Instance(std::string filePath) : Problem<T, D>(filePath) {}
48+
Instance(std::string filePath) : StackAlgo<T, D, I>(filePath) {}
4449
private:
45-
// Functions to implement according to the problem and input
46-
D readInput(std::vector<std::string> line){
47-
std::cout << "Implement readInput for your instance" << std::endl;
48-
return 0;
49-
}
50-
std::shared_ptr<T> initStack(){
51-
std::cout << "Implement initStack for your instance" << std::endl;
52-
std::shared_ptr<T> context(nullptr);
53-
return context;
54-
}
55-
bool popCondition(D data){
56-
std::cout << "Implement mPopCondition for your instance" << std::endl;
57-
return false;
58-
}
59-
void popAction(Data<T, D> elt){
60-
std::cout << "Implement mPopAction for your instance" << std::endl;
61-
}
62-
bool pushCondition(D data){
63-
std::cout << "Implement mPushCondition for your instance" << std::endl;
64-
return true;
65-
}
66-
void pushAction(Data<T, D> elt){
67-
std::cout << "Implement mPushAction for your instance" << std::endl;
68-
}
69-
};
70-
```
50+
// Methods to implement according to the problem and input structure
51+
// Some of those methods might be left empty
52+
D readInput(std::vector<std::string> line);
53+
std::shared_ptr<T> initStack();
7154
72-
### Example with ```T = int``` and ```D = int``` : ```Instance<int,int>```
73-
The context is initialized at 0. The data (in cvs format) is read as a pair of string such that the first string is the data and the second is used to update the context. While the context is more than 0, the stack is poped and the context decreased by 1. If the data is more than 0 then it is pushed.
74-
```cpp
75-
class Instance : public Problem<int, int> {
76-
public:
77-
Instance(std::string filePath) : Problem<int, int>(filePath) {}
55+
bool popCondition(D data);
56+
void prePop(D data);
57+
void postPop(D data, Data<T, D, I> elt);
58+
void noPop(D data);
7859
79-
private:
80-
// Functions to run the stack
81-
int readInput(std::vector<std::string> line) {
82-
int value = std::stoi(line[0]);
83-
setContext(std::stoi(line[1]));
84-
return value;
85-
}
86-
std::shared_ptr<int> initStack() {
87-
std::shared_ptr<int> context(new int(0));
88-
return context;
89-
}
90-
bool popCondition(int data) {
91-
if ((getContext() > 0)) {
92-
return true;
93-
}
94-
return false;
95-
}
96-
void popAction(Data<int, int> elt) {
97-
std::cout << elt.toString() << " <<<< Pop!" << std::endl;
98-
setContext(getContext() - 1);
99-
}
100-
bool pushCondition(int data) {
101-
if (data > 0) {
102-
return true;
103-
}
104-
return false;
105-
}
106-
void pushAction(Data<int, int> elt) {
107-
std::cout << "Push >>>> " << elt.toString() << std::endl;
108-
}
60+
bool pushCondition(D data);
61+
void prePush(Data<T, D, I> elt);
62+
void postPush(Data<T, D, I> elt);
63+
void noPush(D data);
64+
65+
void reportStack();
10966
};
11067
```
111-
112-
## How to run your problem
113-
Suppose the class Instance implement the interface Problem<T,D> (as in some examples above). You can run an instance of your problem described in the input located at <i>filepath</i>. The last command just print an output in th console of your compressed stack after the run.
68+
### How to run your problem
69+
Suppose the class Instance implements the interface ```StackAlgo<T, D, I>```. You can run an instance of your problem described in the input located at <i>filepath</i>. The last command just print an output in the console of your compressed stack after the run.
11470

11571
```cpp
11672
Instance stack(filePath);
11773
stack.run();
11874
stack.println();
11975
```
76+
77+
## Contributing
78+
This project is far from being complete and would benefit greatly from future contributions. Commented code, following the existing file structure is strongly preferred. Please contact one of the author (or create an issue) in case of need. Here is a short sample of possible contributions :
79+
* Use CI (continuous integration). Definitively the most wanted feature
80+
* Extends the compressed stack structure to a dequeue structure (push and pop from top and bottom)
81+
* Add other problems to the examples folder (following, if possible a similar structure)
82+
* Extends the compressed stack structure to a compressed tree search structure
83+
* Dynamic size compressed stack.
84+
85+
86+
## Credits
87+
Although this project is a joint work, based on the theoretical work in [Barba *et al.*](https://arxiv.org/abs/1208.3663), credits belong to specific authors for part of the implementation. The work covering the implementation of the Stack Algorithm framework, the Comrpessed Stack structure and extras functionalities (```include``` and ```extras``` repositories) has been done by [Jean-Francois Baffier](https://github.com/Azzaarehttps://github.com/Azzaare). All the examples and their generating algorithms, along with all the test have been implemented by [Yago Diez](https://github.com/nicill).
88+
89+
## License
90+
This project is an open source software under the MIT license. Please check the ```LICENSE``` file for further information.

‎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
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /