Skip to content

Commit 912e2bc

Browse files
committed
Fix bug when large insertion
1 parent b918983 commit 912e2bc

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

quicked/src/bpm_banded.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,19 @@ void banded_matrix_allocate(
121121
const int64_t k_end = ABS(((int64_t)text_length) - (int64_t)(pattern_length)) + 1;
122122
banded_matrix->cutoff_score = MAX(MAX(k_end, cutoff_score), 65);
123123
banded_matrix->sequence_length_diff = pattern_length - text_length;
124-
banded_matrix->relative_cutoff_score = DIV_CEIL((banded_matrix->cutoff_score - ABS(banded_matrix->sequence_length_diff)), 2);
124+
banded_matrix->relative_cutoff_score = (banded_matrix->cutoff_score - ABS(banded_matrix->sequence_length_diff)) == 0LL ? 0LL :
125+
DIV_CEIL((banded_matrix->cutoff_score - ABS(banded_matrix->sequence_length_diff)), 2);
126+
const int64_t relative_cutoff_score_blocks = banded_matrix->relative_cutoff_score == 0LL ? 0LL : DIV_CEIL(banded_matrix->relative_cutoff_score, BPM_W64_LENGTH);
125127
if (banded_matrix->sequence_length_diff >= 0)
126128
{
127-
banded_matrix->prolog_column_blocks = DIV_CEIL(banded_matrix->relative_cutoff_score, BPM_W64_LENGTH);
129+
banded_matrix->prolog_column_blocks = relative_cutoff_score_blocks;
128130
banded_matrix->effective_bandwidth_blocks = DIV_CEIL(banded_matrix->relative_cutoff_score + banded_matrix->sequence_length_diff, BPM_W64_LENGTH) + 1 + banded_matrix->prolog_column_blocks;
129131
}
130132
else
131133
{
132-
banded_matrix->prolog_column_blocks = DIV_CEIL(banded_matrix->relative_cutoff_score - banded_matrix->sequence_length_diff, BPM_W64_LENGTH);
133-
banded_matrix->effective_bandwidth_blocks = DIV_CEIL(banded_matrix->relative_cutoff_score, BPM_W64_LENGTH) + 1 + banded_matrix->prolog_column_blocks;
134+
banded_matrix->prolog_column_blocks = banded_matrix->relative_cutoff_score - banded_matrix->sequence_length_diff == 0LL ? 0LL :
135+
DIV_CEIL(banded_matrix->relative_cutoff_score - banded_matrix->sequence_length_diff, BPM_W64_LENGTH);
136+
banded_matrix->effective_bandwidth_blocks = relative_cutoff_score_blocks + 1 + banded_matrix->prolog_column_blocks;
134137
}
135138
banded_matrix->effective_bandwidth = banded_matrix->cutoff_score;
136139

@@ -157,7 +160,7 @@ void banded_matrix_allocate(
157160
Pv = (uint64_t *)mm_allocator_malloc(mm_allocator, aux_matrix_size);
158161
Mv = (uint64_t *)mm_allocator_malloc(mm_allocator, aux_matrix_size);
159162
}
160-
int64_t *const scores = (int64_t *)mm_allocator_malloc(mm_allocator, (DIV_CEIL(pattern_length, BPM_W64_LENGTH) + num_words64 / 2) * UINT64_SIZE);
163+
int64_t *const scores = (int64_t *)mm_allocator_malloc(mm_allocator, MAX((DIV_CEIL(pattern_length, BPM_W64_LENGTH) + num_words64 / 2), banded_matrix->effective_bandwidth_blocks) * UINT64_SIZE);
161164
banded_matrix->Mv = Mv;
162165
banded_matrix->Pv = Pv;
163166
banded_matrix->scores = scores;

quicked/src/bpm_hirschberg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ quicked_status_t bpm_compute_matrix_hirschberg(
100100
text_length, text_len_r, SCORE_ONLY, force_scalar);
101101

102102
// vertival position of the first blocks computed on each aligments
103-
int64_t first_block_band_pos_v = text_len < prolog_column_blocks * BPM_W64_LENGTH ? 0 : (text_len / BPM_W64_LENGTH) - (prolog_column_blocks);
104-
int64_t first_block_band_pos_v_r = text_len_r < prolog_column_blocks * BPM_W64_LENGTH ? 0 : (text_len_r / BPM_W64_LENGTH) - (prolog_column_blocks);
103+
int64_t first_block_band_pos_v = (text_len / BPM_W64_LENGTH) - (banded_matrix.prolog_column_blocks);
104+
int64_t first_block_band_pos_v_r = (text_len_r / BPM_W64_LENGTH) - (banded_matrix.prolog_column_blocks);
105105

106106
// Higher and lower cell's position computen in each aligments
107107
int64_t bottom_cell;

quicked/src/quicked.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ quicked_params_t quicked_default_params(void)
317317
.overlap_size = 1,
318318
.force_scalar = false,
319319
.external_timer = false,
320+
.external_allocator = NULL,
320321
};
321322
}
322323

0 commit comments

Comments
 (0)