@@ -455,14 +455,14 @@ template <class T, class D> std::string CompressedStack<T, D>::toString() {
455455// Function push that push the data in explicit and index in partial/compressed
456456template <class T , class D >
457457void CompressedStack<T, D>::push(const Data<T, D> &elt) {
458- int headIndex = getLast (mDepth );
459458 // update the buffer (if buffer size is bigger than 0)
460459 SPData<T, D> ptr_elt = std::make_shared<Data<T, D>>(elt);
461460 mBuffer .push (ptr_elt);
462461 // update the explicit Blocks, with possibly shifting first to second
463462 pushExplicit (ptr_elt);
464463 // update the compressed Blocks at each levels (including fully compressed)
465464 for (int lvl = mDepth - 1 ; lvl > 0 ; lvl--) {
465+ int headIndex = getLast (lvl);
466466 pushCompressed (ptr_elt, lvl, headIndex);
467467 }
468468}
@@ -525,8 +525,7 @@ void CompressedStack<T, D>::pushCompressed(SPData<T, D> elt, int lvl,
525525 int delta = index - startBlock;
526526 if (delta < distBlock) {
527527 // Distance with the current subblock
528- int headSubBlock = getLast (lvl);
529- int startSubBlock = headSubBlock - (headSubBlock - 1 ) % distSubBlock;
528+ int startSubBlock = headIndex - (headIndex - 1 ) % distSubBlock;
530529 int eta = index - startSubBlock;
531530 // compress new element in the top of the current Block
532531 if (eta < distSubBlock) {
@@ -612,11 +611,12 @@ void CompressedStack<T, D>::compress(Block<T, D> block) {
612611==============================================================================*/
613612template <class T , class D >
614613void CompressedStack<T, D>::reconstruct(Problem<T, D> &problem) {
615- Signature<T, D> *sign;
614+ Signature<T, D> *sign = new Signature<T,D>() ;
616615 int lvl;
617616 for (lvl = mDepth ; lvl >= 0 ; lvl--) {
618617 if (lvl == 0 ) {
619618 sign = getSign (0 );
619+ break ;
620620 } else {
621621 if (!empty (lvl, 1 )) {
622622 sign = getSign (1 , lvl);
@@ -627,7 +627,6 @@ void CompressedStack<T, D>::reconstruct(Problem<T, D> &problem) {
627627 }
628628 }
629629 }
630- std::cout << " Reconstruct on " << sign->toString () << std::endl;
631630
632631 std::streampos posReminder = problem.mInput .tellg ();
633632 int indexReminder = problem.mIndex ;
@@ -638,7 +637,10 @@ void CompressedStack<T, D>::reconstruct(Problem<T, D> &problem) {
638637 problem.mInput .clear ();
639638 problem.mInput .seekg (sign->mPosition );
640639
641- int auxSize = std::pow (mSpace , mDepth - lvl + 1 );
640+ int auxSize = mSize ;
641+ if (lvl > 0 ) {
642+ auxSize = std::pow (mSpace , mDepth - lvl + 1 );
643+ }
642644 std::shared_ptr<Stack<T, D>> auxStack =
643645 std::make_shared<CompressedStack<T, D>>(
644646 auxSize, mSpace , mBuffer .mSize , problem.mContext , sign->mPosition );
@@ -649,17 +651,16 @@ void CompressedStack<T, D>::reconstruct(Problem<T, D> &problem) {
649651 swap (problem.mStack , auxStack);
650652
651653 if (lvl == 0 ) {
652- (* auxStack). copyContent (*this );
654+ auxStack-> copyContent (*this );
653655 } else {
654656 // Copy the First component of the reconstructed stack into the main stack
655- int auxDepth = int (ceil (log (auxSize) / log (mSpace ) - .001 )) - 1 ;
657+ int auxDepth = int (ceil (log (auxSize) / log (mSpace ) - .001 ) - 1 ) ;
656658 int delta = mDepth - auxDepth;
657- for (int i = 0 ; i < auxDepth - 1 ; i++) {
658- mSecond .mPartial [delta + i] = (* auxStack). getFirstPartial (i);
659+ for (int i = 1 ; i < auxDepth; i++) {
660+ mSecond .mPartial [delta + i - 1 ] = auxStack-> getFirstPartial (i);
659661 }
660-
661- mSecond .mExplicit = (*auxStack).getFirstExplicit ();
662- mSecond .mSign = (*auxStack).getFirstSign ();
662+ mSecond .mExplicit = auxStack->getFirstExplicit ();
663+ mSecond .mSign = auxStack->getFirstSign ();
663664 }
664665
665666 problem.mIndex = indexReminder;
@@ -721,7 +722,7 @@ void CompressedStack<T, D>::popComponent(int index, int component) {
721722 setSign (component);
722723 } else {
723724 int newLast = getLast (mDepth );
724- setLast (newLast, component );
725+ setLast (component, newLast );
725726 }
726727 if (mDepth > 1 ) {
727728 clear (index, mDepth - 1 , component);
@@ -732,17 +733,18 @@ template <class T, class D>
732733void CompressedStack<T, D>::clear(int index, int lvl, int component) {
733734 if (component == 2 && !empty (lvl, 1 )) {
734735 clear (index, lvl, 1 );
735- }
736- if (single (lvl, component)) {
737- pop_back (lvl, component);
738- if (lvl > 1 ) {
739- clear (index, lvl - 1 , component);
740- } else if (empty (1 , component)) {
741- setSign (component);
742- }
743736 } else {
744- int newLast = getLast (lvl + 1 );
745- propagate (newLast, lvl, component);
737+ if (single (lvl, component)) {
738+ pop_back (lvl, component);
739+ if (lvl > 1 ) {
740+ clear (index, lvl - 1 , component);
741+ } else if (empty (1 , component)) {
742+ setSign (component);
743+ }
744+ } else {
745+ int newLast = getLast (lvl + 1 );
746+ propagate (newLast, lvl, component);
747+ }
746748 }
747749}
748750
0 commit comments