From c12b5e1159ccd7e42cbfd3fb21b43c354c2797f8 Mon Sep 17 00:00:00 2001 From: Martin Sosic Date: Sat, 9 Sep 2017 22:50:34 +0100 Subject: [PATCH] Fixed issue #85. --- edlib/src/edlib.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/edlib/src/edlib.cpp b/edlib/src/edlib.cpp index c3ef618..f26de83 100644 --- a/edlib/src/edlib.cpp +++ b/edlib/src/edlib.cpp @@ -578,13 +578,24 @@ static int myersCalcEditDistanceSemiGlobal( } } - // Every some columns, do some expensive but also more efficient block reducing -> this is important! + // Every some columns, do some expensive but also more efficient block reducing. + // This is important! + // + // Reduce the band by decreasing last block if possible. if (c % STRONG_REDUCE_NUM == 0) { - while (lastBlock >= firstBlock && allBlockCellsLarger(*bl, k)) { + while (lastBlock >= 0 && lastBlock >= firstBlock && allBlockCellsLarger(*bl, k)) { lastBlock--; bl--; Peq_c--; } } + // For HW, even if all cells are > k, there still may be solution in next + // column because starting conditions at upper boundary are 0. + // That means that first block is always candidate for solution, + // and we can never end calculation before last column. + if (mode == EDLIB_MODE_HW && lastBlock == -1) { + lastBlock++; bl++; Peq_c++; + } + // Reduce band by increasing first block if possible. Not applicable to HW. if (mode != EDLIB_MODE_HW) { while (firstBlock <= lastBlock && blocks[firstBlock].score >= k + WORD_SIZE) { firstBlock++; @@ -596,14 +607,6 @@ static int myersCalcEditDistanceSemiGlobal( } } - // For HW, even if all cells are > k, there still may be solution in next - // column because starting conditions at upper boundary are 0. - // That means that first block is always candidate for solution, - // and we can never end calculation before last column. - if (mode == EDLIB_MODE_HW) { - lastBlock = max(0, lastBlock); - } - // If band stops to exist finish if (lastBlock < firstBlock) { *bestScore_ = bestScore;