From c09947bd764acef30201bcca7dc973dd8138bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20G=C3=BCndling?= Date: Wed, 18 Sep 2024 21:56:46 +0200 Subject: [PATCH] move for_each_bit_set to utl --- .pkg | 2 +- include/osr/routing/profiles/foot.h | 10 ++++++---- include/osr/types.h | 17 +++-------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/.pkg b/.pkg index c49cbce..55090a4 100644 --- a/.pkg +++ b/.pkg @@ -25,7 +25,7 @@ [utl] url=git@github.com:motis-project/utl.git branch=master - commit=80df7a6f1e2de4d290c48e9218d48eb9792b7289 + commit=b036489decf04df2c11bb2971312b6bd70781c51 [protozero] url=git@github.com:motis-project/protozero.git branch=master diff --git a/include/osr/routing/profiles/foot.h b/include/osr/routing/profiles/foot.h index 50903dd..57714a4 100644 --- a/include/osr/routing/profiles/foot.h +++ b/include/osr/routing/profiles/foot.h @@ -1,5 +1,7 @@ #pragma once +#include "utl/for_each_bit_set.h" + #include "osr/routing/tracking.h" #include "osr/ways.h" @@ -252,8 +254,8 @@ struct foot { Fn&& f) { auto const p = w.node_properties_[n]; if (p.is_multi_level()) { - for_each_set_bit(get_elevator_multi_levels(w, n), - [&](auto&& l) { f(level_t{l}); }); + utl::for_each_set_bit(get_elevator_multi_levels(w, n), + [&](auto&& l) { f(level_t{l}); }); } else { f(p.from_level()); f(p.to_level()); @@ -271,8 +273,8 @@ struct foot { if (p.is_multi_level()) { auto const levels = get_elevator_multi_levels(w, n); - return has_bit_set(levels, to_idx(a)) && - (b == level_t::invalid() || has_bit_set(levels, to_idx(b))); + return utl::has_bit_set(levels, to_idx(a)) && + (b == level_t::invalid() || utl::has_bit_set(levels, to_idx(b))); } else { return (a == p.from_level() || a == p.to_level()) && (b == level_t::invalid() || b == p.from_level() || diff --git a/include/osr/types.h b/include/osr/types.h index 86f42b6..bbff37d 100644 --- a/include/osr/types.h +++ b/include/osr/types.h @@ -3,6 +3,8 @@ #include #include +#include "utl/for_each_bit_set.h" + #include "ankerl/cista_adapter.h" #include "cista/containers/bitvec.h" @@ -148,26 +150,13 @@ constexpr auto const kLevelBits = cista::constexpr_trailing_zeros( using level_bits_t = std::uint32_t; -constexpr bool has_bit_set(level_bits_t const levels, unsigned const bit) { - return (levels & (level_bits_t{1U} << bit)) != 0U; -} - -template -constexpr void for_each_set_bit(level_bits_t const levels, Fn&& f) { - for (auto bit = 0U; bit != sizeof(level_bits_t) * 8U; ++bit) { - if (has_bit_set(levels, bit)) { - f(bit); - } - } -} - constexpr std::tuple get_levels( bool const has_level, level_bits_t const levels) noexcept { if (!has_level) { return {level_t{to_level(0.F)}, level_t{to_level(0.F)}, false}; } auto from = level_t::invalid(), to = level_t::invalid(); - for_each_set_bit(levels, [&](auto&& bit) { + utl::for_each_set_bit(levels, [&](auto&& bit) { from == level_t::invalid() // ? from = level_t{bit} : to = level_t{bit};