Skip to content

Commit b0678dd

Browse files
committed
Simplify usage of shared_ptr<Data<T,D> in SPData<T,D>
1 parent af0905f commit b0678dd

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

include/buffer.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class Buffer{
3232

3333
// Getters
3434
Data<T,D> top(int k);
35-
std::shared_ptr<Data<T,D>> getPointer(int k);
35+
SPData<T,D> getPointer(int k);
3636

3737
// Setters
3838
void setStart();
39-
void setData(std::shared_ptr<Data<T,D>> elt, int index);
39+
void setData(SPData<T,D> elt, int index);
4040

4141
// Push and Pop
42-
void push(std::shared_ptr<Data<T,D>> elt);
43-
void pop(std::shared_ptr<Data<T,D>> elt);
42+
void push(SPData<T,D> elt);
43+
void pop(SPData<T,D> elt);
4444

4545
// IO
4646
std::string toString();
@@ -77,7 +77,7 @@ Data<T,D> Buffer<T,D>::top(int k){
7777
}
7878

7979
template <class T, class D>
80-
std::shared_ptr<Data<T,D>> Buffer<T,D>::getPointer(int k){
80+
SPData<T,D> Buffer<T,D>::getPointer(int k){
8181
if (k < mSize) {
8282
int index = (k + mStart - 1) % mSize; // -1 match the start of vectors at 0
8383
return mExplicit[index];
@@ -93,7 +93,7 @@ void Buffer<T,D>::setStart(){
9393
mStart = (mStart + 1) % mSize;
9494
}
9595
template <class T, class D>
96-
void Buffer<T,D>::setData(std::shared_ptr<Data<T,D>> elt, int id){
96+
void Buffer<T,D>::setData(SPData<T,D> elt, int id){
9797
int index = (id + mStart - 1) % mSize; // -1 match the start of vectors at 0
9898
mExplicit[index] = elt;
9999
}
@@ -102,14 +102,14 @@ void Buffer<T,D>::setData(std::shared_ptr<Data<T,D>> elt, int id){
102102
Stack Functions: push, pop
103103
==============================================================================*/
104104
template <class T, class D>
105-
void Buffer<T,D>::push(std::shared_ptr<Data<T,D>> elt){
105+
void Buffer<T,D>::push(SPData<T,D> elt){
106106
if (mSize > 0) {
107107
setData(elt, mStart+1);
108108
}
109109
}
110110

111111
template <class T, class D>
112-
void Buffer<T,D>::pop(std::shared_ptr<Data<T,D>> elt){
112+
void Buffer<T,D>::pop(SPData<T,D> elt){
113113
setStart();
114114
setData(elt, mSize);
115115
}

include/component.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Component{
2828
void clearExplicit(int space);
2929

3030
// Push and pop
31-
void pushExplicit(std::shared_ptr<Data<T,D>> elt);
31+
void pushExplicit(SPData<T,D> elt);
3232
void push(Signature<T,D> sign, int lvl);
3333
Data<T,D> top();
3434
Signature<T,D> top(int lvl);
@@ -116,7 +116,7 @@ bool Component<T,D>::isExplicitEmpty(){
116116
}
117117

118118
template <class T, class D>
119-
void Component<T,D>::pushExplicit(std::shared_ptr<Data<T,D>> elt){
119+
void Component<T,D>::pushExplicit(SPData<T,D> elt){
120120
mExplicit.push_back(elt);
121121
}
122122
template <class T, class D>

include/compressedStack.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ class CompressedStack: public Stack<T,D>{
4545
Block<T,D> getFirstPartial(int lvl);
4646
Block<T,D> getCompressed();
4747
ExplicitPointer<T,D> getFirstExplicit();
48-
std::shared_ptr<Data<T,D>> getExplicitData(int k);
48+
SPData<T,D> getExplicitData(int k);
4949

5050
// IO
5151
std::string toString();
5252

5353
// Push Internals
54-
void pushExplicit(std::shared_ptr<Data<T,D>> elt);
55-
void pushCompressed(std::shared_ptr<Data<T,D>> elt, int lvl, std::streampos position);
54+
void pushExplicit(SPData<T,D> elt);
55+
void pushCompressed(SPData<T,D> elt, int lvl, std::streampos position);
5656
Data<T,D> top();
5757
int topIndex();
5858
void compress();
@@ -146,7 +146,7 @@ ExplicitPointer<T,D> CompressedStack<T,D>::getFirstExplicit(){
146146
}
147147

148148
template <class T, class D>
149-
std::shared_ptr<Data<T,D>> CompressedStack<T,D>::getExplicitData(int k){
149+
SPData<T,D> CompressedStack<T,D>::getExplicitData(int k){
150150
if (k <= (int) mFirst.mExplicit.size()) {
151151
return mFirst.mExplicit[k-1];
152152
} else {
@@ -209,7 +209,7 @@ void CompressedStack<T,D>::resetBlock(Signature<T,D> sign, int lvl){
209209
template <class T, class D>
210210
void CompressedStack<T,D>::push(const Data<T,D> &elt, std::streampos position){
211211
// update the buffer (if buffer size is bigger than 0)
212-
std::shared_ptr<Data<T,D>> ptr_elt = std::make_shared<Data<T,D>>(elt);
212+
SPData<T,D> ptr_elt = std::make_shared<Data<T,D>>(elt);
213213
mBuffer.push(ptr_elt);
214214
// update the explicit Blocks, with possibly shifting first to second
215215
pushExplicit(ptr_elt);
@@ -222,9 +222,9 @@ void CompressedStack<T,D>::push(const Data<T,D> &elt, std::streampos position){
222222

223223
// Function push for the Explicit members of the stack
224224
template <class T, class D>
225-
void CompressedStack<T,D>::pushExplicit(std::shared_ptr<Data<T,D>> elt){
225+
void CompressedStack<T,D>::pushExplicit(SPData<T,D> elt){
226226
int index = elt->mIndex;
227-
std::shared_ptr<Data<T,D>> eltPtr = elt;
227+
SPData<T,D> eltPtr = elt;
228228
Signature<T,D> sign (index, mPosition, mContext, mBuffer);
229229

230230
// If the explicit datas of component 1 are empty we push
@@ -259,7 +259,7 @@ void CompressedStack<T,D>::pushExplicit(std::shared_ptr<Data<T,D>> elt){
259259

260260
// Function push for the part. and fully compressed members of the stack
261261
template <class T, class D>
262-
void CompressedStack<T,D>::pushCompressed(std::shared_ptr<Data<T,D>> elt, int lvl, std::streampos position){
262+
void CompressedStack<T,D>::pushCompressed(SPData<T,D> elt, int lvl, std::streampos position){
263263
int distSubBlock = std::pow(mSpace,(mDepth - lvl));
264264
int distBlock = distSubBlock * mSpace;
265265
int index = elt->mIndex;
@@ -437,14 +437,14 @@ void CompressedStack<T,D>::reconstruct(Problem<T,D> &problem, const Signature<T,
437437

438438
template <class T, class D>
439439
void CompressedStack<T,D>::popBuffer(){
440-
std::shared_ptr<Data<T,D>> elt = getExplicitData(mBuffer.mSize);
440+
SPData<T,D> elt = getExplicitData(mBuffer.mSize);
441441
mBuffer.pop(elt);
442442
}
443443

444444
template <class T, class D>
445445
Data<T,D> CompressedStack<T,D>::pop(Problem<T,D> &problem){
446446
popBuffer();
447-
std::shared_ptr<Data<T,D>> elt;
447+
SPData<T,D> elt;
448448
if (mFirst.mExplicit.empty()) {
449449
if (mSecond.mExplicit.empty()) {
450450
// Reconstruct the compressed stack with the first available signature

include/data.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ class Data{
3939
D mData;
4040
};
4141

42+
template<class T, class D> using SPData = std::shared_ptr<Data<T,D>>;
43+
4244
template<class T, class D> using Explicit = std::vector<Data<T,D>>;
4345
template<class T, class D> Explicit<T,D> initExplicit();
4446

45-
template<class T, class D> using ExplicitPointer = std::vector<std::shared_ptr<Data<T,D>>>;
47+
template<class T, class D> using ExplicitPointer = std::vector<SPData<T,D>>;
4648
template<class T, class D> ExplicitPointer<T,D> initExplicitPointer();
4749

4850
/*==============================================================================

0 commit comments

Comments
 (0)