Skip to content

Commit 7a319b3

Browse files
committed
Basic structure of the comrpessed stack
1 parent c68ac4e commit 7a319b3

File tree

13 files changed

+353
-0
lines changed

13 files changed

+353
-0
lines changed

compressedStack.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**** Compressed Stack: implementations ****/
2+
#include "compressedStack.hpp"
3+
4+
/** Constructors **/
5+
template <class T, class D>
6+
Component<T,D>::Component(int space, int depth)
7+
{
8+
mSign = nullptr;
9+
10+
Levels<T> partial = initLevels<T>(space, depth);
11+
mPartial = partial;
12+
13+
Explicit<D> xplicit;
14+
xplicit.resize(space);
15+
mExplicit = xplicit;
16+
}
17+
18+
template <class T, class D>
19+
CompressedStack<T,D>::CompressedStack(int size, int space)
20+
{
21+
mSize = size;
22+
mSpace = space;
23+
mDepth = 0;
24+
}

compressedStack.hpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**** Compressed Stack: declarations ****/
2+
#include "sign.hpp"
3+
#include "stack.hpp"
4+
5+
/* Component of a Compressed Stack */
6+
template <class T, class D>
7+
class Component
8+
{
9+
public:
10+
Component<T,D>(int space, int depth);
11+
12+
// Setters
13+
void setSignature(Signature<T> sign);
14+
15+
private:
16+
Levels<T> mPartial;
17+
Explicit<D> mExplicit;
18+
Signature<T>* mSign;
19+
};
20+
21+
22+
/* Compressed Stack itself */
23+
template <class T, class D>
24+
class CompressedStack:Stack<D>
25+
{
26+
public:
27+
CompressedStack<T,D>(int size, int space);
28+
private:
29+
// Structure constraints
30+
int mSize; // (Expected) size of the input in #elements
31+
int mSpace; // Maximum space order of the compressed stack
32+
int mDepth; // Depth (#levels of compression) based on size and space
33+
34+
// Position of previous input (before reading)
35+
int mPosition;
36+
37+
// First, Second, and Compressed components
38+
Component<T,D> mFirst;
39+
Component<T,D> mSecond;
40+
Block<T> mCompressed;
41+
};

data.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** Data class : implementation **/
2+
#include "data.hpp"
3+
4+
/** Getters **/
5+
template <class D>
6+
int Data<D>::getIndex()
7+
{
8+
return mIndex;
9+
}
10+
template <class D>
11+
D Data<D>::getData()
12+
{
13+
return mData;
14+
}

data.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** Data class : declaration **/
2+
#include <vector>
3+
#include <stack>
4+
5+
template <class D>
6+
class Data
7+
{
8+
public:
9+
// Getters
10+
int getIndex();
11+
D getData();
12+
13+
private:
14+
int mIndex;
15+
D mData;
16+
};
17+
18+
template<class D>
19+
using Explicit = std::stack<Data<D>,std::vector<Data<D>>>;

exampleyago.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Created by yago on 16/04/19.
3+
//
4+
5+
#ifndef ONEDTRAJECTORIES_ONEDTIMEPOINT_H
6+
#define ONEDTRAJECTORIES_ONEDTIMEPOINT_H
7+
8+
9+
#include "RunningTime.h"
10+
11+
class oneDTimePoint {
12+
13+
double position;
14+
RunningTime t;
15+
16+
public:
17+
18+
oneDTimePoint(); //Default constructor
19+
oneDTimePoint(double pos, RunningTime tprima)//parameter Constructor
20+
{
21+
position=pos;
22+
t=tprima;
23+
}
24+
oneDTimePoint(double pos, int h,int m,int s) //parameter Constructor 2
25+
{
26+
position=pos;
27+
t=RunningTime(h,m,s);
28+
}
29+
30+
oneDTimePoint(const oneDTimePoint &pt); //Copy constructor
31+
32+
// accessor methods
33+
double getPos()const{return position;};
34+
RunningTime getTime()const{return t;};
35+
36+
37+
void operator=(oneDTimePoint tprima) //assignment
38+
{
39+
position=tprima.getPos();
40+
t=tprima.getTime();
41+
}
42+
43+
void write(std::ostream& os)
44+
{
45+
os << "running at km point: (" << position << ") at time " << t;
46+
}
47+
friend std::ostream& operator<<(std::ostream& os, oneDTimePoint tp )
48+
{
49+
tp.write(os);
50+
return os;
51+
}
52+
53+
54+
};
55+
56+
57+
#endif //ONEDTRAJECTORIES_ONEDTIMEPOINT_H

main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Main file of the compressed stack library
2+
3+
#include "sign.hpp"

normalStack.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**** Normal Stack: definition ****/
2+
#include "normalStack.hpp"
3+
4+
template <class D>
5+
Data<D> NormalStack<D>::pop()
6+
{
7+
return mDatas.pop();
8+
}
9+
10+
template <class D>
11+
void NormalStack<D>::push(Data<D> data)
12+
{
13+
mDatas.push(data);
14+
}
15+
16+
template <class D>
17+
Data<D>* NormalStack<D>::top(int k)
18+
{
19+
int index = mDdatas.size() - k;
20+
return &(data[index]);
21+
}

normalStack.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**** Normal Stack: declaration ****/
2+
#include "stack.hpp"
3+
4+
template <class D>
5+
class NormalStack:Stack<D>
6+
{
7+
public:
8+
Data<D> pop();
9+
void push(Data<D> newdata);
10+
Data<D>* top(int k);
11+
12+
private:
13+
Explicit<D> mDatas; // vector of Data
14+
};

problem.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**** Problem : implementation ****/
2+
#include "problem.hpp"
3+
4+
5+
/** Constructors **/
6+
template <class T, class D>
7+
Problem<T,D>::Problem(std::string fileName)
8+
{
9+
std::ifstream ifstr;
10+
ifstr.open(fileName, std::ifstream::in);
11+
mInput = ifstr;
12+
}

problem.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**** Problem : declaration ****/
2+
#include "stack.hpp"
3+
#include <stdbool.h>
4+
#include <fstream>
5+
#include <string>
6+
7+
template <class T, class D>
8+
class Problem
9+
{
10+
public:
11+
Problem<T,D>(std::string fileName);
12+
13+
// Functions of the problem
14+
//void init();
15+
//D read();
16+
17+
private:
18+
// Input/Ouput
19+
std::ifstream mInput;
20+
std::ofstream* mOutput; // output file is optional
21+
22+
// Stack Functions: defined by user
23+
void (*mInitStack)();
24+
D (*mReadInput)();
25+
bool (*mPopCondition)();
26+
void (*mPopAction)();
27+
bool (*mPushCondition)();
28+
void (*mPushAction)();
29+
30+
// Problem internal during run
31+
T* mContext;
32+
int mIndex;
33+
34+
// Stack: Normal or Compressed
35+
Stack<D> mStack;
36+
};

0 commit comments

Comments
 (0)