File tree Expand file tree Collapse file tree 12 files changed +296
-0
lines changed
Expand file tree Collapse file tree 12 files changed +296
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ };
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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>>>;
Original file line number Diff line number Diff line change 1+ // Main file of the compressed stack library
2+
3+ #include " sign.hpp"
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ };
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ };
Original file line number Diff line number Diff line change 1+ /* ** Signature : implementation ***/
2+ #include " sign.hpp"
3+
4+ /* * Constructors **/
5+ // Signature
6+ template <class T >
7+ Signature<T>::Signature(int index, int position, T context)
8+ {
9+ mFirst = index;
10+ mLast = index;
11+ mPosition = position;
12+ mContext = context;
13+ }
14+
15+ /* * Setters **/
16+ template <class T >
17+ void Signature<T>::setLast(int index)
18+ {
19+ mLast = index;
20+ }
21+
22+ /* * Getters **/
23+ template <class T >
24+ int Signature<T>::getFirst()
25+ {
26+ return mFirst ;
27+ }
28+ template <class T >
29+ int Signature<T>::getLast()
30+ {
31+ return mLast ;
32+ }
33+ template <class T >
34+ int Signature<T>::getPosition()
35+ {
36+ return mPosition ;
37+ }
38+ template <class T >
39+ T Signature<T>::getContext()
40+ {
41+ return mContext ;
42+ }
43+
44+ /* * New Block and Levels **/
45+ template <class T >
46+ Block<T> initBlock (int space)
47+ {
48+ Block<T> block;
49+ block.resize (space);
50+ return block;
51+ }
52+
53+ template <class T >
54+ Levels<T> initLevels (int space, int depth)
55+ {
56+ Levels<T> levels;
57+ for (int lvl = 1 ; lvl < depth; lvl++)
58+ {
59+ Block<T> block = initBlock<T>(space);
60+ levels.push (block);
61+ }
62+ levels.resize (depth-1 );
63+
64+ return levels;
65+ }
You can’t perform that action at this time.
0 commit comments