+ x = n - 2;
+ posOfSuccEndmarker = n-1;
+ for(ulong i=0; i<sampleLength; i++) {
+ // Find next sampled text position
+ while ((posOfSuccEndmarker - x) % samplerate != 0)
+ {
+ --x;
+ if (tsbuilder[x] == '\0')
+ posOfSuccEndmarker = x--;
+ }
+ assert((*positions)[i] < n);
+ ulong j = sampled->rank1((*positions)[i]);
+
+ assert(j != 0); // if (j==0) j=sampleLength;
+
+ TextPosition textPos = (x==n-1)?0:x+1;
+ (*suffixDocId)[j-1] = textStorage->DocIdAtTextPos(textPos);
+
+ assert((*suffixDocId)[j-1] < numberOfTexts);
+ // calculate offset from text start:
+ (*suffixes)[j-1] = textPos - textStorage->TextStartPos((*suffixDocId)[j-1]);
+ --x;
+ if (tsbuilder[x] == '\0')
+ posOfSuccEndmarker = x--;
+ }
+
+ delete positions;