Skip to content

Commit 9bb6bc9

Browse files
committed
Added pop function to Buffer
1 parent 0f22fdf commit 9bb6bc9

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

include/buffer.hpp

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

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

3637
// Setters
3738
void setStart();
3839
void setData(std::shared_ptr<Data<T,D>> elt, int index);
3940

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

4445
// IO
4546
std::string toString();
@@ -75,6 +76,15 @@ Data<T,D> Buffer<T,D>::top(int k){
7576
throw "Access to a top element bigger than the size of the buffer";
7677
}
7778

79+
template <class T, class D>
80+
std::shared_ptr<Data<T,D>> Buffer<T,D>::getPointer(int k){
81+
if (k < mSize) {
82+
int index = (k + mStart - 1) % mSize; // -1 match the start of vectors at 0
83+
return mExplicit[index];
84+
}
85+
throw "Access to a top element bigger than the size of the buffer";
86+
}
87+
7888
/*==============================================================================
7989
Setters
8090
==============================================================================*/
@@ -99,8 +109,9 @@ void Buffer<T,D>::push(std::shared_ptr<Data<T,D>> elt){
99109
}
100110

101111
template <class T, class D>
102-
void Buffer<T,D>::pop(){
112+
void Buffer<T,D>::pop(std::shared_ptr<Data<T,D>> elt){
103113
setStart();
114+
setData(elt, mSize);
104115
}
105116

106117
/*==============================================================================

include/compressedStack.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ 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);
4849

4950
// IO
5051
std::string toString();
@@ -58,6 +59,7 @@ class CompressedStack: public Stack<T,D>{
5859
void resetBlock(Signature<T,D> sign, int lvl);
5960

6061
// Pop Internals
62+
void popBuffer();
6163
void reconstruct(Problem<T,D> &problem);
6264
void reconstruct(Problem<T,D> &problem,const Signature<T,D> &sign, int lvl);
6365
void popFirst();
@@ -143,6 +145,15 @@ ExplicitPointer<T,D> CompressedStack<T,D>::getFirstExplicit(){
143145
return mFirst.mExplicit;
144146
}
145147

148+
template <class T, class D>
149+
std::shared_ptr<Data<T,D>> CompressedStack<T,D>::getExplicitData(int k){
150+
if (k <= (int) mFirst.mExplicit.size()) {
151+
return mFirst.mExplicit[k-1];
152+
} else {
153+
return mFirst.mSign.mBuffer.getPointer(k - 1 - mFirst.mExplicit.size());
154+
}
155+
}
156+
146157
/*==============================================================================
147158
IO : toString
148159
==============================================================================*/
@@ -424,8 +435,15 @@ void CompressedStack<T,D>::reconstruct(Problem<T,D> &problem, const Signature<T,
424435
mSecond.mExplicit = (*auxStack).getFirstExplicit();
425436
}
426437

438+
template <class T, class D>
439+
void CompressedStack<T,D>::popBuffer(){
440+
std::shared_ptr<Data<T,D>> elt = getExplicitData(mBuffer.mSize);
441+
mBuffer.pop(elt);
442+
}
443+
427444
template <class T, class D>
428445
Data<T,D> CompressedStack<T,D>::pop(Problem<T,D> &problem){
446+
popBuffer();
429447
std::shared_ptr<Data<T,D>> elt;
430448
if (mFirst.mExplicit.empty()) {
431449
if (mSecond.mExplicit.empty()) {

0 commit comments

Comments
 (0)