diff --git a/include/seqan3/search/detail/search_scheme_algorithm.hpp b/include/seqan3/search/detail/search_scheme_algorithm.hpp index 7084b41dc9..68f794d8c2 100644 --- a/include/seqan3/search/detail/search_scheme_algorithm.hpp +++ b/include/seqan3/search/detail/search_scheme_algorithm.hpp @@ -244,7 +244,7 @@ inline auto search_scheme_block_info(search_scheme_t const & search_scheme, size for (uint8_t block_id = 0; block_id < rest; ++block_id) ++blocks_length[block_id]; - for (uint8_t search_id = 0; search_id < search_scheme.size(); ++search_id) + for (size_t search_id = 0; search_id < search_scheme.size(); ++search_id) { auto const & search = search_scheme[search_id]; @@ -783,7 +783,7 @@ inline void search_ss(index_t const & index, // retrieve cumulative block lengths and starting position auto const block_info = search_scheme_block_info(search_scheme, std::ranges::size(query)); - for (uint8_t search_id = 0; search_id < search_scheme.size(); ++search_id) + for (size_t search_id = 0; search_id < search_scheme.size(); ++search_id) { auto const & search = search_scheme[search_id]; auto const & [blocks_length, start_pos] = block_info[search_id]; diff --git a/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp b/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp index 14d97f5128..bbaac450fc 100644 --- a/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp +++ b/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp @@ -335,7 +335,7 @@ class bi_fm_index_cursor size_type new_parent_lb = fwd_lb, new_parent_rb = fwd_rb; - sdsl_char_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel + sdsl_sigma_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel while (c < sigma && !bidirectional_search(index->fwd_fm.index, index->fwd_fm.index.comp2char[c], @@ -352,7 +352,8 @@ class bi_fm_index_cursor parent_lb = new_parent_lb; parent_rb = new_parent_rb; - _last_char = c; + assert(c <= std::numeric_limits::max()); + _last_char = static_cast(c); ++depth; return true; @@ -387,7 +388,7 @@ class bi_fm_index_cursor size_type new_parent_lb = rev_lb, new_parent_rb = rev_rb; - sdsl_char_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel + sdsl_sigma_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel while (c < sigma && !bidirectional_search(index->rev_fm.index, index->rev_fm.index.comp2char[c], @@ -404,7 +405,8 @@ class bi_fm_index_cursor parent_lb = new_parent_lb; parent_rb = new_parent_rb; - _last_char = c; + assert(c <= std::numeric_limits::max()); + _last_char = static_cast(c); ++depth; return true; @@ -685,7 +687,7 @@ class bi_fm_index_cursor assert(index != nullptr && query_length() > 0); - sdsl_char_type c = _last_char + 1; + sdsl_sigma_type c = _last_char + 1; while (c < sigma && !bidirectional_search_cycle(index->fwd_fm.index, @@ -702,7 +704,8 @@ class bi_fm_index_cursor if (c != sigma) { - _last_char = c; + assert(c <= std::numeric_limits::max()); + _last_char = static_cast(c); return true; } @@ -744,7 +747,7 @@ class bi_fm_index_cursor assert(index != nullptr && query_length() > 0); - sdsl_char_type c = _last_char + 1; + sdsl_sigma_type c = _last_char + 1; while (c < sigma && !bidirectional_search_cycle(index->rev_fm.index, index->rev_fm.index.comp2char[c], @@ -760,7 +763,8 @@ class bi_fm_index_cursor if (c != sigma) { - _last_char = c; + assert(c <= std::numeric_limits::max()); + _last_char = static_cast(c); return true; } diff --git a/include/seqan3/search/fm_index/fm_index_cursor.hpp b/include/seqan3/search/fm_index/fm_index_cursor.hpp index 3faf86020a..f63e5fcaa3 100644 --- a/include/seqan3/search/fm_index/fm_index_cursor.hpp +++ b/include/seqan3/search/fm_index/fm_index_cursor.hpp @@ -260,7 +260,7 @@ class fm_index_cursor // store all cursors at once in a private std::array of cursors assert(index != nullptr); - sdsl_char_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel + sdsl_sigma_type c = 1; // NOTE: start with 0 or 1 depending on implicit_sentintel size_type _lb = node.lb, _rb = node.rb; while (c < sigma && !backward_search(index->index, index->index.comp2char[c], _lb, _rb)) { @@ -271,7 +271,8 @@ class fm_index_cursor { parent_lb = node.lb; parent_rb = node.rb; - node = {_lb, _rb, node.depth + 1, c}; + assert(c <= std::numeric_limits::max()); + node = {_lb, _rb, node.depth + 1, static_cast(c)}; return true; } return false; @@ -406,7 +407,7 @@ class fm_index_cursor // parent_lb > parent_rb --> invalid interval assert(parent_lb <= parent_rb); - sdsl_char_type c = node.last_char + 1; + sdsl_sigma_type c = node.last_char + 1; size_type _lb = parent_lb, _rb = parent_rb; while (c < sigma && !backward_search(index->index, index->index.comp2char[c], _lb, _rb)) @@ -416,7 +417,8 @@ class fm_index_cursor if (c != sigma) // Collection has additional sentinel as delimiter { - node = {_lb, _rb, node.depth, c}; + assert(c <= std::numeric_limits::max()); + node = {_lb, _rb, node.depth, static_cast(c)}; return true; } return false; diff --git a/test/unit/utility/math_test.cpp b/test/unit/utility/math_test.cpp index 4fb0ad7957..3609d6e4ad 100644 --- a/test/unit/utility/math_test.cpp +++ b/test/unit/utility/math_test.cpp @@ -25,7 +25,7 @@ TYPED_TEST(unsigned_operations, floor_log2) constexpr size_t one2 = seqan3::detail::floor_log2(0b0011); constexpr size_t two1 = seqan3::detail::floor_log2(0b0101); constexpr size_t two2 = seqan3::detail::floor_log2(0b0111); - constexpr size_t seven = seqan3::detail::floor_log2(0b10010010); + constexpr size_t seven = seqan3::detail::floor_log2(0b1001'0010); EXPECT_EQ(zero, 0u); EXPECT_EQ(one1, 1u); EXPECT_EQ(one2, 1u); @@ -36,8 +36,8 @@ TYPED_TEST(unsigned_operations, floor_log2) for (uint8_t log2_value = 0; log2_value < seqan3::detail::bits_of; ++log2_value) { unsigned_t start = unsigned_t{1u} << log2_value; - unsigned_t end = start << 1u; - for (unsigned_t n = start, k = 0u; n < end && k < max_iterations; ++n, ++k) + unsigned_t end = static_cast(std::min(start, max_iterations) + start); + for (unsigned_t n = start; n < end; ++n) { EXPECT_EQ(seqan3::detail::floor_log2(n), log2_value); EXPECT_EQ(std::floor(std::log2(n)), log2_value) << "If this fails this might be a floating point rounding " @@ -54,7 +54,7 @@ TYPED_TEST(unsigned_operations, ceil_log2) constexpr size_t two = seqan3::detail::ceil_log2(0b0011); constexpr size_t three1 = seqan3::detail::ceil_log2(0b0101); constexpr size_t three2 = seqan3::detail::ceil_log2(0b0111); - constexpr size_t eight = seqan3::detail::ceil_log2(0b10010010); + constexpr size_t eight = seqan3::detail::ceil_log2(0b1001'0010); EXPECT_EQ(zero, 0u); EXPECT_EQ(one, 1u); EXPECT_EQ(two, 2u); @@ -65,13 +65,13 @@ TYPED_TEST(unsigned_operations, ceil_log2) for (uint8_t log2_value = 0; log2_value < seqan3::detail::bits_of; ++log2_value) { unsigned_t start = unsigned_t{1u} << log2_value; - unsigned_t end = start << 1u; + unsigned_t end = static_cast(std::min(start, max_iterations) + start); EXPECT_EQ(seqan3::detail::ceil_log2(start), log2_value); EXPECT_EQ(std::ceil(std::log2(start)), log2_value) << "ceil_log2 of " << start << " should be " << log2_value << "; If this fails this might be a floating point rounding " << "error on your machine."; - for (unsigned_t n = start + 1u, k = 0u; n < end && k < max_iterations; ++n, ++k) + for (unsigned_t n = start + 1u; n < end; ++n) { EXPECT_EQ(seqan3::detail::ceil_log2(n), log2_value + 1u);