@@ -375,7 +375,8 @@ RLCSA::locate(usint index, bool steps) const
375
375
usint
376
376
RLCSA::inverseLocate (usint location) const
377
377
{
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.
379
380
380
381
// Inverse-locate the given location in BWT space, and convert back to SA
381
382
// space before returning.
@@ -434,23 +435,43 @@ RLCSA::directLocate(usint index, bool steps) const
434
435
usint
435
436
RLCSA::directInverseLocate (usint location) const
436
437
{
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
438
451
// before the given text location.
439
452
pair_type last_sample = this ->sa_samples ->inverseSA (location);
440
453
441
454
// 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) {
444
457
// We're not at the desired text location, so we must be before it.
445
458
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 ;
448
461
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
450
463
// that psi returns BWT coordinates, so we have to convert back to SA
451
464
// coordinates.
452
- last_sample.first = (this ->psi (last_sample.first ) -
465
+ last_sample.second = (this ->psi (last_sample.second ) -
453
466
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" ;
454
475
}
455
476
456
477
// Return the answer in BWT coordinates. It will probably be immediately
0 commit comments