Skip to content

Commit 82da03e

Browse files
committed
Merge branch 'compressedPush'
2 parents 342007f + 43b1d15 commit 82da03e

File tree

12 files changed

+1059
-458
lines changed

12 files changed

+1059
-458
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*.exe
2727
*.out
2828
*.app
29+
*/smartstack
2930

3031

3132
CMakeCache.txt

CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
44
# Project Name
55
project(smartstack)
66

7+
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
8+
# Select the build path in function of the build type: release, debug, ...
9+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/${CMAKE_BUILD_TYPE_LOWER})
10+
711
include(CheckCXXCompilerFlag)
812
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
913
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
@@ -15,6 +19,29 @@ else()
1519
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
1620
endif()
1721

22+
# Default build mode is Release with debug information
23+
IF(NOT CMAKE_BUILD_TYPE)
24+
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
25+
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
26+
FORCE)
27+
ENDIF(NOT CMAKE_BUILD_TYPE)
28+
29+
## Configure the different type of build
30+
# Release
31+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
32+
# Debug
33+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
34+
# RelWithDebInfo
35+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
36+
# MinSizeRel
37+
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
38+
39+
# Basic options for all builds
40+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Weffc++ -Wshadow -ansi")
41+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wshadow")
42+
# Might need to be fixed for retrocompatibility or temporary
43+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++0x-compat -Wno-unused")
44+
1845
#Bring the headers into the project
1946
include_directories(${PROJECT_SOURCE_DIR}/include)
2047

@@ -27,3 +54,25 @@ message("inc_dirs = ${inc_dirs}")
2754

2855
# Executable
2956
add_executable(smartstack ${SOURCES})
57+
58+
59+
# Description of the different builds
60+
# +---------------+--------------+--------------+----------|
61+
# | | optimization | assert works | stripped |
62+
# +---------------+--------------+--------------+----------|
63+
# | Debug | no | yes | no |
64+
# | Release | full | no | yes |
65+
# | RelWithDebInfo| good | no | no |
66+
# | MinSizeRel | size | no | yes |
67+
# +---------------+--------------+--------------+----------|
68+
69+
# Alias for cmake commands
70+
# alias cmakedebug='cmake $1 -DCMAKE_BUILD_TYPE=DEBUG'
71+
# alias cmakerelease='cmake $1 -DCMAKE_BUILD_TYPE=RELEASE'
72+
# alias cmakerelwithdebinfo='cmake $1 -DCMAKE_BUILD_TYPE=RELWITHDEBINFO'
73+
# alias cmakeminsizerel='cmake $1 -DCMAKE_BUILD_TYPE=MINSIZEREL'
74+
75+
# Example for debug (first line only if the directory doesn't exist)
76+
# mkdir build_directory
77+
# cd build_directory
78+
# cmakedebug ..

build/cmakereadme.txt

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

include/buffer.hpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#ifndef BUFFER
2+
#define BUFFER
3+
4+
/*==============================================================================
5+
Includes
6+
==============================================================================*/
7+
#include "data.hpp"
8+
#include <vector>
9+
#include <string>
10+
#include <iostream>
11+
#include <memory>
12+
13+
/*==============================================================================
14+
Class : template (D datas)
15+
Extensions :
16+
Aliases :
17+
Friends -> CompressedStack
18+
<-
19+
==============================================================================*/
20+
template <class T, class D> class CompressedStack; // Required for the friendship
21+
template <class T, class D>
22+
class Buffer{
23+
friend class CompressedStack<T,D>;
24+
25+
private:
26+
// Constructor
27+
Buffer<T,D>(int size = 0);
28+
29+
// Getters
30+
Data<T,D> top(int k);
31+
32+
// Setters
33+
void setStart();
34+
void setData(std::shared_ptr<Data<T,D>> elt, int index);
35+
36+
// Push and Pop
37+
void push(std::shared_ptr<Data<T,D>> elt);
38+
void pop();
39+
40+
// IO
41+
std::string toString();
42+
43+
// Members
44+
int mSize;
45+
int mStart;
46+
ExplicitPointer<T,D> mExplicit;
47+
};
48+
49+
/*==============================================================================
50+
Constructors
51+
==============================================================================*/
52+
template <class T, class D>
53+
Buffer<T,D>::Buffer(int size){
54+
mSize = size;
55+
mStart = 0;
56+
57+
ExplicitPointer<T,D> xplicit = initExplicitPointer<T,D>();
58+
xplicit.reserve(size);
59+
mExplicit = xplicit;
60+
}
61+
62+
/*==============================================================================
63+
Getters
64+
==============================================================================*/
65+
template <class T, class D>
66+
Data<T,D> Buffer<T,D>::top(int k){
67+
if (k < mSize) {
68+
int index = (k + mStart - 1) % mSize; // -1 match the start of vectors at 0
69+
return *(mExplicit[index]);
70+
}
71+
throw "Access to a top element bigger than the size of the buffer";
72+
}
73+
74+
/*==============================================================================
75+
Setters
76+
==============================================================================*/
77+
template <class T, class D>
78+
void Buffer<T,D>::setStart(){
79+
mStart = (mStart + 1) % mSize;
80+
}
81+
template <class T, class D>
82+
void Buffer<T,D>::setData(std::shared_ptr<Data<T,D>> elt, int id){
83+
int index = (id + mStart - 1) % mSize; // -1 match the start of vectors at 0
84+
mExplicit[index] = elt;
85+
}
86+
87+
/*==============================================================================
88+
Stack Functions: push, pop
89+
==============================================================================*/
90+
template <class T, class D>
91+
void Buffer<T,D>::push(std::shared_ptr<Data<T,D>> elt){
92+
if (mSize > 0) {
93+
setData(elt, mStart+1);
94+
}
95+
}
96+
97+
template <class T, class D>
98+
void Buffer<T,D>::pop(){
99+
setStart();
100+
}
101+
102+
/*==============================================================================
103+
IO : toString
104+
==============================================================================*/
105+
template <class T, class D>
106+
std::string Buffer<T,D>::toString(){
107+
std::string str;
108+
str = "\t\tBuffer size is " + std::to_string(mSize);
109+
str += " and start at index " + std::to_string(mStart) + "\n";
110+
str += explicitPointerToString(mExplicit);
111+
return str;
112+
}
113+
114+
#endif /* BUFFER */

include/component.hpp

Lines changed: 108 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,76 @@
11
#ifndef COMPONENT
22
#define COMPONENT
33

4-
/**** Compressed Stack: declarations ****/
4+
/*==============================================================================
5+
Includes
6+
==============================================================================*/
57
#include "sign.hpp"
68
#include "stack.hpp"
79
#include <string>
10+
#include <memory>
811

9-
/* Component of a Compressed Stack */
12+
/*==============================================================================
13+
Class : template (T context, D datas)
14+
Extensions :
15+
Aliases :
16+
Friends -> CompressedStack
17+
<- Data, Signature
18+
==============================================================================*/
19+
template <class T, class D> class CompressedStack; // Required for the friendship
1020
template <class T, class D>
11-
class Component
12-
{
13-
public:
21+
class Component{
22+
friend class CompressedStack<T,D>;
23+
24+
private:
1425
Component<T,D>(int space, int depth);
1526

1627
// Setters
17-
void setSignature(Signature<T> sign);
18-
void setLastSign(int index);
28+
void clearExplicit(int space);
29+
30+
// Push and pop
31+
void pushExplicit(std::shared_ptr<Data<T,D>> elt);
32+
void push(Signature<T,D> sign, int lvl);
33+
Data<T,D> top();
34+
Signature<T,D> top(int lvl);
35+
int topIndex(int lvl = 0);
1936

2037
// IO
2138
std::string toString();
22-
void print();
23-
void println();
2439

25-
private:
26-
Levels<T> mPartial;
27-
Explicit<D> mExplicit;
28-
Signature<T>* mSign;
40+
// State
41+
bool isempty();
42+
bool isempty(int lvl);
43+
bool isExplicitEmpty();
44+
45+
Levels<T,D> mPartial;
46+
ExplicitPointer<T,D> mExplicit;
47+
Signature<T,D> mSign;
2948
};
3049

31-
/** Constructors **/
50+
/*==============================================================================
51+
Constructors
52+
==============================================================================*/
3253
template <class T, class D>
3354
Component<T,D>::Component(int space, int depth)
34-
{
35-
mSign = nullptr;
55+
:mSign(0, std::streampos (0), std::shared_ptr<T>(nullptr)){
3656

37-
Levels<T> partial = initLevels<T>(space, depth);
57+
Levels<T,D> partial = initLevels<T,D>(space, depth);
3858
mPartial = partial;
3959

40-
Explicit<D> xplicit;
41-
xplicit = initExplicit<D>();
60+
ExplicitPointer<T,D> xplicit = initExplicitPointer<T,D>();
4261
xplicit.reserve(space);
4362
mExplicit = xplicit;
4463
}
4564

46-
/** IO **/
47-
template <class T>
48-
std::string levelsToStringInComponent(Levels<T> levels)
49-
{
65+
/*==============================================================================
66+
IO : levelsToStringInComponent, toString
67+
==============================================================================*/
68+
template <class T, class D>
69+
std::string levelsToString(Levels<T,D> levels){
5070
std::string str;
5171
str = "";
5272
int index = 0;
53-
for (typename Levels<T>::iterator it = levels.begin() ; it != levels.end(); ++it)
73+
for (typename Levels<T,D>::iterator it = levels.begin() ; it != levels.end(); ++it)
5474
{
5575
index++;
5676
str += "\t\t\tLevel" + std::to_string(index) + "->\n";
@@ -60,15 +80,75 @@ std::string levelsToStringInComponent(Levels<T> levels)
6080
}
6181

6282
template <class T, class D>
63-
std::string Component<T,D>::toString()
64-
{
83+
std::string Component<T,D>::toString(){
6584
std::string str;
66-
str = levelsToStringInComponent(mPartial);
85+
str = levelsToString(mPartial);
6786
str += "\t\t\tExplicit->\n";
68-
str += explicitToString(mExplicit);
87+
str += explicitPointerToString(mExplicit);
6988
str += "\t\t\tSignature->\n";
7089
//str += (&mSign).toString() + "\n";
7190
return str;
7291
}
7392

93+
/*==============================================================================
94+
Stack Functions: push, pop, top, topIndex, isempty, isExplicitEmpty
95+
==============================================================================*/
96+
template <class T, class D>
97+
bool Component<T,D>::isempty(){
98+
bool b = bool (mSign.mContext);
99+
return !b;
100+
}
101+
102+
template <class T, class D>
103+
bool Component<T,D>::isempty(int lvl){
104+
bool b;
105+
if (lvl > int(mPartial.size())) {
106+
b = isExplicitEmpty();
107+
} else {
108+
b = (mPartial[lvl]).empty();
109+
}
110+
return b;
111+
}
112+
113+
template <class T, class D>
114+
bool Component<T,D>::isExplicitEmpty(){
115+
return (mExplicit.empty());
116+
}
117+
118+
template <class T, class D>
119+
void Component<T,D>::pushExplicit(std::shared_ptr<Data<T,D>> elt){
120+
mExplicit.push_back(elt);
121+
}
122+
template <class T, class D>
123+
void Component<T,D>::push(Signature<T,D> sign, int lvl){
124+
mPartial[lvl].push_back(sign);
125+
}
126+
127+
template <class T, class D>
128+
Data<T,D> Component<T,D>::top(){
129+
return *(mExplicit.back());
130+
}
131+
template <class T, class D>
132+
Signature<T,D> Component<T,D>::top(int lvl){
133+
return mPartial[lvl].back();
134+
}
135+
136+
template <class T, class D>
137+
int Component<T,D>::topIndex(int lvl){
138+
if (lvl == 0) {
139+
return top().mIndex;
140+
} else {
141+
return top(lvl).mLast;
142+
}
143+
}
144+
145+
/*==============================================================================
146+
Setters
147+
==============================================================================*/
148+
template <class T, class D>
149+
void Component<T,D>::clearExplicit(int space){
150+
mExplicit.clear();
151+
mExplicit.reserve(space);
152+
}
153+
74154
#endif /* COMPONENT */

0 commit comments

Comments
 (0)