Skip to content

Commit 943883b

Browse files
committed
Fix integer overflow bug on lower bound when max range is set to maximum uint value
1 parent fb83375 commit 943883b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

newmap/unique_counts.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ def binary_search(index_filename: Path,
289289
# Otherwise keep the current unique length
290290
unique_lengths[counted_positions])
291291

292+
# If we have a k-mer count of 1 and the current length queried is the
293+
# same as the lower bound (i.e. can't get smaller for a unique count)
294+
# This position has finished searching
295+
finished_search[counted_positions] = np.where(
296+
count_list == 1,
297+
current_length_query[counted_positions] ==
298+
lower_length_bound[counted_positions],
299+
finished_search[counted_positions])
300+
301+
# If we have a k-mer count > 1 and the current length queried is the
302+
# same as the uppper bound (i.e. can't find a unique length or larger)
303+
# This position has finished searching
304+
finished_search[counted_positions] = np.where(
305+
count_list > 1,
306+
current_length_query[counted_positions] ==
307+
upper_length_bound[counted_positions],
308+
finished_search[counted_positions])
309+
292310
# Update the query length and bounds for the next iteration
293311

294312
# Lower the upper bounds of our search range on positions where
@@ -314,13 +332,6 @@ def binary_search(index_filename: Path,
314332
(upper_length_bound[counted_positions] / 2) +
315333
(lower_length_bound[counted_positions] / 2)).astype(data_type)
316334

317-
# If we have reduced our bounds to overlapping we have finished
318-
# searching on this position
319-
finished_search[counted_positions] = \
320-
finished_search[counted_positions] | \
321-
(upper_length_bound[counted_positions] <
322-
lower_length_bound[counted_positions])
323-
324335
iteration_count += 1
325336

326337
verbose_print(verbose,

0 commit comments

Comments
 (0)