Skip to content

Commit 8f7c7cd

Browse files
committed
Corrected bug in propagateFirst
1 parent 29deaa4 commit 8f7c7cd

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

include/compressedStack.hpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class CompressedStack: public Stack<T,D>{
7676
Signature<T,D> getFirstSign();
7777
Block<T,D> getSmartCompress(int lvl);
7878
Signature<T,D> getBottomSign();
79+
Signature<T,D> getTop2Partial(int lvl);
7980

8081
// IO
8182
std::string toString();
@@ -159,6 +160,20 @@ Block<T,D> CompressedStack<T,D>::getFirstPartial(int lvl){
159160
return mFirst.mPartial[lvl];
160161
}
161162

163+
template <class T, class D>
164+
Signature<T,D> CompressedStack<T,D>::getTop2Partial(int lvl){
165+
int sizeFirst = mFirst.mPartial[lvl].size();
166+
int sizeSecond = mSecond.mPartial[lvl].size();
167+
if (sizeFirst + sizeSecond < 2) {
168+
throw "Incorrect access in smartIndex/getTop2Partial";
169+
}
170+
if (sizeFirst >= 2) {
171+
return mFirst.mPartial[lvl][sizeFirst - 2];
172+
} else {
173+
return mSecond.mPartial[lvl][sizeSecond + sizeFirst - 2];
174+
}
175+
}
176+
162177
template <class T, class D>
163178
Block<T,D> CompressedStack<T,D>::getCompressed(){
164179
return mCompressed;
@@ -388,7 +403,8 @@ void CompressedStack<T,D>::pushCompressed(SPData<T,D> elt, int lvl, int headInde
388403
int delta = index - startBlock;
389404
if (delta < distBlock) {
390405
// Distance with the current subblock
391-
int startSubBlock = headIndex - (headIndex - 1) % distSubBlock;
406+
int headSubBlock = mFirst.mPartial[lvl].back().mLast;
407+
int startSubBlock = headSubBlock - (headSubBlock - 1) % distSubBlock;
392408
int eta = index - startSubBlock;
393409
// compress new element in the top of the current Block
394410
if (eta < distSubBlock) {
@@ -500,24 +516,11 @@ int CompressedStack<T,D>::smartIndex(int index){
500516
}
501517

502518
for (int lvl = mDepth - 2; lvl >= 0; lvl--) {
503-
if (mFirst.mPartial[lvl].empty()) {
504-
if (!mSecond.single(lvl)) {
505-
return (index - (index % (int) std::pow(mSpace, mDepth - lvl - 1)));
506-
} else {
507-
int size = mSecond.mPartial[lvl].size();
508-
if (size > 1) {
509-
return mSecond.mPartial[lvl][size-2].mLast;
510-
}
511-
}
512-
} else {
513-
if (!mFirst.single(lvl)) {
514-
return (index - (index % (int) std::pow(mSpace, mDepth - lvl - 1)));
515-
} else {
516-
int size = mFirst.mPartial[lvl].size();
517-
if (size > 1) {
518-
return mFirst.mPartial[lvl][size-2].mLast;
519-
}
520-
}
519+
if (!mFirst.single(lvl)) {
520+
521+
}
522+
if (mFirst.mPartial[lvl].size() + mSecond.mPartial[lvl].size() > 1) {
523+
return getTop2Partial(lvl).mLast;
521524
}
522525
}
523526

@@ -601,7 +604,7 @@ void CompressedStack<T,D>::emptyFirst(int index, int lvl){
601604

602605
template <class T, class D>
603606
void CompressedStack<T,D>::emptySecond(int index, int lvl){
604-
if (mFirst.single(lvl)) {
607+
if (mFirst.single(lvl) || !mFirst.mPartial[lvl].empty()) {
605608
emptyFirst(index, lvl);
606609
} else {
607610
if (mSecond.single(lvl)) {
@@ -632,9 +635,13 @@ Data<T,D> CompressedStack<T,D>::pop(Problem<T,D> &problem){
632635
SPData<T,D> elt;
633636
if (mFirst.mExplicit.empty() && mSecond.mExplicit.empty()) {
634637
// Reconstruct the compressed stack with the first available signature
635-
reconstruct(problem);
638+
reconstruct(problem);
636639
}
637640
if (mFirst.mExplicit.empty()) {
641+
if (mSecond.mExplicit.empty()) {
642+
problem.println();
643+
// exit(0);
644+
}
638645
elt = mSecond.mExplicit.back();
639646
popSecond((*elt).mIndex);
640647
} else {
@@ -664,7 +671,11 @@ template <class T, class D>
664671
int CompressedStack<T,D>::topIndex(){
665672
if (mFirst.mExplicit.empty()) {
666673
if (mSecond.mExplicit.empty()) {
667-
return mCompressed.back().mLast;
674+
if (!mCompressed.empty()) {
675+
return mCompressed.back().mLast;
676+
} else {
677+
return 0;
678+
}
668679
}
669680
return (*(mSecond.mExplicit.back())).mIndex;
670681
}

include/problem.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Problem<T,D>::Problem(std::string fileName)
9494

9595
std::vector<std::string> parameters=readHeader();
9696

97-
int n,p,b;
97+
int p,b,n=0;
9898
bool foundP=false;
9999
bool foundBuffer=false;
100100

0 commit comments

Comments
 (0)