@@ -16,7 +16,7 @@ template <class T, class D>
1616class CompressedStack : public Stack <D>
1717{
1818public:
19- CompressedStack<T,D>(int size, int space, int buffer, std::shared_ptr<T> context);
19+ CompressedStack<T,D>(int size, int space, int buffer, std::shared_ptr<T> context, std::streampos position );
2020
2121 // Internals
2222 Data<D> top (int k);
@@ -58,7 +58,7 @@ class CompressedStack: public Stack<D>
5858
5959/* * Constructors **/
6060template <class T , class D >
61- CompressedStack<T,D>::CompressedStack(int size, int space, int buffer, std::shared_ptr<T> context)
61+ CompressedStack<T,D>::CompressedStack(int size, int space, int buffer, std::shared_ptr<T> context, std::streampos position )
6262: mFirst (size,space)
6363, mSecond (size,space)
6464, mBuffer (buffer)
@@ -67,7 +67,7 @@ CompressedStack<T,D>::CompressedStack(int size, int space, int buffer, std::shar
6767 mSpace = space;
6868 mDepth = (int ) ceil (log (size)/log (space)-.1 ); // - 1;
6969
70- mPosition = 0 ;
70+ mPosition = position ;
7171
7272 mCompressed = initBlock<T>(mSpace );
7373
@@ -79,22 +79,16 @@ template <class T, class D>
7979std::string CompressedStack<T,D>::toString()
8080{
8181 std::string str;
82- std::cout << " Debug CompressedStack::toString 1" << std::endl;
8382 str = " \t Compressed Stack with " + std::to_string (mSize ) + " elements, " ;
8483 str += std::to_string (mSpace ) + " space order, " ;
8584 str += std::to_string (mDepth ) + " depth.\n " ;
8685 str += " \t\t First Component\n " ;
87- std::cout << " Debug CompressedStack::toString 2" << std::endl;
8886 str += mFirst .toString ();
8987 str += " \t\t Second Component\n " ;
90- std::cout << " Debug CompressedStack::toString 3" << std::endl;
9188 str += mSecond .toString ();
9289 str += " \t\t Fully Compressed\n " ;
93- std::cout << " Debug CompressedStack::toString 4" << std::endl;
9490 str += blockToString (mCompressed );
95- std::cout << " Debug CompressedStack::toString 5" << std::endl;
9691 str += mBuffer .toString ();
97- std::cout << " Debug CompressedStack::toString 6" << std::endl;
9892 return str;
9993}
10094
@@ -134,23 +128,70 @@ void CompressedStack<T,D>::push(Data<D> elt){
134128// Function push for the Explicit members of the stack
135129template <class T , class D >
136130void CompressedStack<T,D>::pushExplicit(std::shared_ptr<Data<D>> elt){
137- std::shared_ptr<Data<D>> ptr = elt;
138- if (mFirst .isempty ()) {
139- mFirst .push (ptr);
140- std::shared_ptr<Signature<T>> sign (new Signature<T> (ptr->getIndex (), mPosition , mContext ));
141- mFirst .setSignature (sign);
131+ int index = elt->getIndex ();
132+ std::shared_ptr<Data<D>> eltPtr = elt;
133+ Signature<T> sign (index, mPosition , mContext );
134+
135+ // If the explicit datas of component 1 are empty we push
136+ if (mFirst .isExplicitEmpty ()) {
137+ mFirst .pushExplicit (eltPtr);
138+ std::shared_ptr<Signature<T>> signPtr (&sign);
139+ mFirst .setSignature (signPtr);
142140 }
141+ // We check if thoses explicit datas are full
143142 else {
144- int headIndex = 0 ;
143+ int headIndex = mFirst .topIndex ();
144+ int startBlock = headIndex - (headIndex - 1 ) % mSpace ;
145+ if (index - startBlock < mSpace ) {
146+ mFirst .pushExplicit (eltPtr);
147+ mFirst .setLastSign (index);
148+ } else {
149+ if ((mDepth == 1 ) && (!(mSecond .isExplicitEmpty ()))) {
150+ if (mCompressed .empty ()) {
151+ mCompressed .push_back (mSecond .getSign ());
152+ } else {
153+ (mCompressed .back ()).setLast (mSecond .getLastSign ());
154+ }
155+ }
156+ std::shared_ptr<Signature<T>> signPtr = mFirst .getSignPtr ();
157+ mSecond .setSignature (signPtr);
158+ mFirst .setSignature (signPtr);
159+ mSecond .setExplicit (mFirst .getExplicit ());
160+ mFirst .clearExplicit (mSpace );
161+ mFirst .pushExplicit (eltPtr);
162+ }
145163 }
146-
147-
148164}
149165
150166// Function push for the part. and fully compressed members of the stack
151167template <class T , class D >
152168void CompressedStack<T,D>::pushCompressed(std::shared_ptr<Data<D>> elt, int lvl){
153-
169+ int distSubBlock = std::pow (mSpace ,(mDepth - lvl));
170+ int distBlock = distSubBlock * mSpace ;
171+ int index = elt->getIndex ();
172+
173+ if (mFirst .isempty (lvl)) {
174+ Signature<T> sign (index, mPosition , mContext );
175+ mFirst .push (sign, lvl);
176+ } else {
177+ int headIndex = mFirst .topIndex (lvl);
178+ int startBlock = headIndex - (headIndex - 1 ) % distBlock;
179+ // distance of the new index and current block
180+ int delta = index - startBlock + 1 ;
181+ if (delta <= distBlock) {
182+ // Distance with the current subblock
183+ int startSubBlock = headIndex - (headIndex - 1 ) % distSubBlock;
184+ int eta = index - startSubBlock + 1 ;
185+ // compress new element in the top of the current Block
186+ if (eta <= distSubBlock) {
187+ int lengthSubBlock = 0 ;
188+ } else {
189+ /* code */
190+ }
191+ } else {
192+ /* code */
193+ }
194+ }
154195}
155196
156197template <class T , class D >
0 commit comments