Skip to content

Commit

Permalink
move for_each_bit_set to utl
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Sep 18, 2024
1 parent 403ded1 commit c09947b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[utl]
[email protected]:motis-project/utl.git
branch=master
commit=80df7a6f1e2de4d290c48e9218d48eb9792b7289
commit=b036489decf04df2c11bb2971312b6bd70781c51
[protozero]
[email protected]:motis-project/protozero.git
branch=master
Expand Down
10 changes: 6 additions & 4 deletions include/osr/routing/profiles/foot.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "utl/for_each_bit_set.h"

#include "osr/routing/tracking.h"
#include "osr/ways.h"

Expand Down Expand Up @@ -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());
Expand All @@ -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() ||
Expand Down
17 changes: 3 additions & 14 deletions include/osr/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cinttypes>
#include <filesystem>

#include "utl/for_each_bit_set.h"

#include "ankerl/cista_adapter.h"

#include "cista/containers/bitvec.h"
Expand Down Expand Up @@ -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 <typename Fn>
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<level_t, level_t, bool> 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};
Expand Down

0 comments on commit c09947b

Please sign in to comment.