@@ -375,7 +375,8 @@ RLCSA::locate(usint index, bool steps) const
375375usint
376376RLCSA::inverseLocate (usint location) const
377377{
378- if (!(this ->support_locate ) || location >= this ->data_size ) { return this ->data_size ; }
378+ if (!(this ->support_locate )) { return this ->data_size ; }
379+ // TODO: Check for out-of-bounds locations somehow.
379380
380381 // Inverse-locate the given location in BWT space, and convert back to SA
381382 // space before returning.
@@ -434,23 +435,43 @@ RLCSA::directLocate(usint index, bool steps) const
434435usint
435436RLCSA::directInverseLocate (usint location) const
436437{
437- // Get the SA value and text location (in that order) of the last SA sample
438+
439+ std::cout << " Dumping SA" << std::endl;
440+
441+ for (usint i = 0 ; i <= this ->data_size ; i++)
442+ {
443+ if (this ->sa_samples ->isSampled (i))
444+ {
445+ std::cout << " SA[" << i << " ] = " << this ->sa_samples ->getSampleAt (i) << std::endl;
446+ }
447+ }
448+
449+ std::cout << " Un-locating " << location << std::endl;
450+ // Get the SA value and SA index (in that order) of the last SA sample
438451 // before the given text location.
439452 pair_type last_sample = this ->sa_samples ->inverseSA (location);
440453
441454 // TODO: catch the (size, size) sentinel.
442-
443- while (last_sample.second != location) {
455+ std::cout << " SA[ " << last_sample. second << " ] = " << last_sample. first << std::endl;
456+ while (last_sample.first < location) {
444457 // We're not at the desired text location, so we must be before it.
445458
446- // Advance the text location by 1
447- last_sample.second += 1 ;
459+ // Advance the text location (SA value) by 1
460+ last_sample.first += 1 ;
448461
449- // Advance the SA position to that corresponding to the next character. Note
462+ // Advance the SA index to that corresponding to the next character. Note
450463 // that psi returns BWT coordinates, so we have to convert back to SA
451464 // coordinates.
452- last_sample.first = (this ->psi (last_sample.first ) -
465+ last_sample.second = (this ->psi (last_sample.second ) -
453466 this ->number_of_sequences );
467+
468+ std::cout << " SA[" << last_sample.second << " ] = " << last_sample.first << std::endl;
469+ }
470+
471+ if (last_sample.first != location) {
472+ // We managed to start on the wrong side of what we're trying to locate;
473+ // inverseSA lied to us.
474+ throw " Somehow skipped desired inverse locate position" ;
454475 }
455476
456477 // Return the answer in BWT coordinates. It will probably be immediately
0 commit comments