Skip to content

Commit c80dd73

Browse files
committed
assume
1 parent d9a4839 commit c80dd73

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎include/gl/graph.hpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,9 +1351,13 @@ class graph final {
13511351

13521352
template <bool FollowApiPolicy = true>
13531353
gl_attr_force_inline void _verify_vertex_id(const id_type vertex_id) const {
1354-
if constexpr (not FollowApiPolicy or std::same_as<api_policy_tag, api::strict_t>)
1354+
if constexpr (not FollowApiPolicy or std::same_as<api_policy_tag, api::strict_t>) {
13551355
if (not this->has_vertex(vertex_id)) [[unlikely]]
13561356
throw std::invalid_argument(std::format("Got invalid vertex id [{}]", vertex_id));
1357+
}
1358+
else {
1359+
[[assume(this->has_vertex(vertex_id))]];
1360+
}
13571361
}
13581362

13591363
template <bool FollowApiPolicy = true>
@@ -1364,14 +1368,18 @@ class graph final {
13641368
}
13651369

13661370
void _verify_edge(const edge_type& edge) const {
1367-
if constexpr (std::same_as<api_policy_tag, api::strict_t>)
1371+
if constexpr (std::same_as<api_policy_tag, api::strict_t>) {
13681372
if (not this->_is_valid_edge(edge)) [[unlikely]]
13691373
throw std::invalid_argument(std::format(
13701374
"Got invalid edge [id = {}, vertices = ({}, {})]",
13711375
edge.id(),
13721376
edge.source(),
13731377
edge.target()
13741378
));
1379+
}
1380+
else {
1381+
[[assume(this->_is_valid_edge(edge))]];
1382+
}
13751383
}
13761384

13771385
[[nodiscard]] bool _is_valid_edge(const edge_type& edge) const noexcept {

‎include/gl/impl/base/adjacency_list.hpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct incidence_item {
3535

3636
namespace detail {
3737

38-
// TODO: rename to find_edge or sth
3938
template <
4039
traits::c_instantiation_of<incidence_item> AdjListItem,
4140
traits::c_api_policy_tag ApiPolicyTag>
@@ -44,14 +43,18 @@ template <
4443
) {
4544
const auto it = std::ranges::find(edge_list, edge.id(), &AdjListItem::edge_id);
4645

47-
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>)
46+
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>) {
4847
if (it == edge_list.end())
4948
throw std::invalid_argument(std::format(
5049
"Got invalid edge [id = {} | vertices = ({}, {})]",
5150
edge.id(),
5251
edge.source(),
5352
edge.target()
5453
));
54+
}
55+
else {
56+
[[assume(it != edge_list.end())]];
57+
}
5558

5659
return it;
5760
}

‎include/gl/impl/base/adjacency_matrix.hpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ class adjacency_matrix;
2727

2828
namespace detail {
2929

30-
// TODO: rename to get_edge_id or sth
3130
template <traits::c_api_policy_tag ApiPolicyTag>
3231
[[nodiscard]] auto& get_edge_entry(auto& id_matrix, const auto& edge) {
3332
// get the edge and validate the address
3433
const auto [source_id, target_id] = edge.incident_vertices();
3534
auto& edge_id = id_matrix[to_idx(source_id)][to_idx(target_id)];
3635

37-
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>)
36+
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>) {
3837
if (edge.id() != edge_id)
3938
throw std::invalid_argument(std::format(
4039
"Got invalid edge [id = {} | vertices = ({}, {})]", edge.id(), source_id, target_id
4140
));
41+
}
42+
else {
43+
[[assume(edge.id() == edge_id)]];
44+
}
4245

4346
return edge_id;
4447
}
@@ -47,7 +50,7 @@ template <traits::c_api_policy_tag ApiPolicyTag, traits::c_id_type IdType>
4750
inline void check_edge_override(
4851
const auto& id_matrix, const IdType source_id, const IdType target_id
4952
) {
50-
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>)
53+
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>) {
5154
if (const auto edge_id = id_matrix[to_idx(source_id)][to_idx(target_id)];
5255
edge_id != invalid_id)
5356
throw std::logic_error(std::format(
@@ -56,6 +59,10 @@ inline void check_edge_override(
5659
source_id,
5760
target_id
5861
));
62+
}
63+
else {
64+
[[assume(id_matrix[to_idx(source_id)][to_idx(target_id)] == invalid_id)]];
65+
}
5966
}
6067

6168
} // namespace detail

‎include/gl/impl/base/flat_adjacency_matrix.hpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ template <traits::c_api_policy_tag ApiPolicyTag, traits::c_id_type IdType>
2929
const auto [source_id, target_id] = edge.incident_vertices();
3030
auto& edge_id = id_matrix[to_idx(source_id), to_idx(target_id)];
3131

32-
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>)
32+
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>) {
3333
if (edge.id() != edge_id)
3434
throw std::invalid_argument(std::format(
3535
"Got invalid edge [id = {} | vertices = ({}, {})]", edge.id(), source_id, target_id
3636
));
37+
}
38+
else {
39+
[[assume(edge.id() == edge_id)]];
40+
}
3741

3842
return edge_id;
3943
}
@@ -42,7 +46,7 @@ template <traits::c_api_policy_tag ApiPolicyTag, traits::c_id_type IdType>
4246
inline void check_edge_override(
4347
const flat_matrix<IdType>& id_matrix, const IdType source_id, const IdType target_id
4448
) {
45-
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>)
49+
if constexpr (std::same_as<ApiPolicyTag, api::strict_t>) {
4650
if (const auto edge_id = id_matrix[to_idx(source_id), to_idx(target_id)];
4751
edge_id != invalid_id)
4852
throw std::logic_error(std::format(
@@ -51,6 +55,10 @@ inline void check_edge_override(
5155
source_id,
5256
target_id
5357
));
58+
}
59+
else {
60+
[[assume(id_matrix[to_idx(source_id), to_idx(target_id)] == invalid_id)]];
61+
}
5462
}
5563

5664
} // namespace detail

‎include/hgl/util.hpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ namespace hgl {
2323
/// > To get a detailed overview of these shared utilities, please refer to the GL module's @ref GL-Util documentation page.
2424
namespace util {
2525

26-
// TODO: add doc comments
27-
2826
using gl::util::all_equal;
2927
using gl::util::is_constant;
3028
using gl::util::range_size;

0 commit comments

Comments
 (0)