Skip to content

Commit 2623a03

Browse files
committed
no i dupa - ten sam durny false positive z array | join
1 parent b0f0473 commit 2623a03

21 files changed

Lines changed: 135 additions & 114 deletions

.clangd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ CompileFlags:
88
- -Wextra
99
- -Wcast-align
1010
- -Wconversion
11-
- -Wsign-conversion
1211
- -Wunreachable-code
1312
- -Wuninitialized
1413
- -Wunused

include/gl/graph.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "gl/impl/impl_tags.hpp"
1010
#include "gl/io/stream_options_manipulator.hpp"
1111
#include "gl/util/ranges.hpp"
12+
#include <sys/types.h>
1213

1314
#include <set>
1415

@@ -212,7 +213,7 @@ class graph final {
212213
}
213214
}
214215

215-
gl_attr_force_inline void remove_vertex(const size_type vertex_id) {
216+
gl_attr_force_inline void remove_vertex(const id_type vertex_id) {
216217
this->_verify_vertex_id(vertex_id);
217218
this->_remove_vertex_impl(vertex_id);
218219
}

include/gl/impl/adjacency_list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class adjacency_list final {
297297
edge_item.edge_id = invalid_id; // edge was removed
298298
else
299299
// shift by the number of removed IDs < edge-id
300-
edge_item.edge_id -= std::ranges::distance(removed_edge_ids.begin(), it);
300+
edge_item.edge_id -= static_cast<id_type>(it - removed_edge_ids.begin());
301301

302302
// align the vertex id
303303
edge_item.vertex_id -= edge_item.vertex_id > removed_vertex_id;

include/gl/topology/cycle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ template <traits::c_graph GraphType>
1717
GraphType graph{n_vertices};
1818

1919
for (id_type source_id = initial_id; source_id < n_vertices; ++source_id)
20-
graph.add_edge(source_id, (source_id + 1uz) % n_vertices);
20+
graph.add_edge(source_id, static_cast<id_type>((source_id + 1uz) % n_vertices));
2121

2222
return graph;
2323
}
@@ -36,7 +36,7 @@ template <traits::c_graph GraphType>
3636
GraphType graph{n_vertices};
3737

3838
for (id_type source_id = initial_id; source_id < n_vertices; ++source_id) {
39-
const auto target_id = (source_id + 1uz) % n_vertices;
39+
const auto target_id = static_cast<id_type>((source_id + 1uz) % n_vertices);
4040
graph.add_edge(source_id, target_id);
4141
graph.add_edge(target_id, source_id);
4242
}

include/hgl/conversion.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,10 @@ requires std::same_as<typename G::traits_type::implementation_tag, gl::impl::fla
294294

295295
template <gl::traits::c_undirected_graph G>
296296
[[nodiscard]] G incidence_graph(const traits::c_undirected_hypergraph auto& h) {
297+
using g_id_type = typename G::id_type;
298+
297299
G g{h.order() + h.size()};
298-
const auto align_edge_id = [shift = h.order()](const auto eid) -> gl::default_id_type {
300+
const auto align_edge_id = [shift = static_cast<g_id_type>(h.order())](const auto eid) -> g_id_type {
299301
return eid + shift;
300302
};
301303

@@ -321,7 +323,7 @@ template <gl::traits::c_directed_graph G>
321323
using g_id_type = typename G::id_type;
322324

323325
G g{h.order() + h.size()};
324-
const auto align_edge_id = [shift = h.order()](const auto eid) -> gl::default_id_type {
326+
const auto align_edge_id = [shift = static_cast<g_id_type>(h.order())](const auto eid) -> g_id_type {
325327
return eid + shift;
326328
};
327329

include/hgl/impl/flat_incidence_list.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ class flat_incidence_list<hgl::undirected_t, ImplTag> final {
237237
return this->_storage[to_idx(id)];
238238
}
239239
else { // incident with minor
240-
return std::views::iota(initial_id_v<size_type>, this->_storage.size())
241-
| std::views::filter([this, minor_id = id](size_type major_idx) {
242-
return detail::contains(this->_storage[major_idx], minor_id);
240+
return std::views::iota(initial_id_v<id_type>, this->_storage.size())
241+
| std::views::filter([this, minor_id = id](id_type major_id) {
242+
return detail::contains(this->_storage[to_idx(major_id)], minor_id);
243243
});
244244
}
245245
}
@@ -551,10 +551,10 @@ class flat_incidence_list<hgl::bf_directed_t, ImplTag> final {
551551
| std::views::join;
552552
}
553553
else { // get minor
554-
return std::views::iota(initial_id_v<size_type>, this->_tail_storage.size())
555-
| std::views::filter([this, minor_id = id](size_type major_idx) {
556-
return detail::contains(this->_tail_storage[major_idx], minor_id)
557-
or detail::contains(this->_head_storage[major_idx], minor_id);
554+
return std::views::iota(initial_id_v<id_type>, this->_tail_storage.size())
555+
| std::views::filter([this, minor_id = id](id_type major_id) {
556+
return detail::contains(this->_tail_storage[to_idx(major_id)], minor_id)
557+
or detail::contains(this->_head_storage[to_idx(major_id)], minor_id);
558558
});
559559
}
560560
}
@@ -566,11 +566,11 @@ class flat_incidence_list<hgl::bf_directed_t, ImplTag> final {
566566
return std::invoke(storage_proj, this)[to_idx(id)];
567567
}
568568
else { // get minor
569-
return std::views::iota(initial_id_v<size_type>, this->_tail_storage.size())
569+
return std::views::iota(initial_id_v<id_type>, this->_tail_storage.size())
570570
| std::views::filter(
571571
[this, &storage = std::invoke(storage_proj, this), minor_id = id](
572-
size_type major_idx
573-
) { return detail::contains(storage[major_idx], minor_id); }
572+
id_type major_id
573+
) { return detail::contains(storage[to_idx(major_id)], minor_id); }
574574
);
575575
}
576576
}

include/hgl/impl/incidence_list.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ class incidence_list<hgl::undirected_t, ImplTag> final {
190190
return std::views::all(this->_major_storage[to_idx(id)]);
191191
}
192192
else { // incident with minor
193-
return std::views::iota(initial_id_v<size_type>, this->_major_storage.size())
194-
| std::views::filter([this, minor_id = id](size_type major_idx) {
195-
return this->_contains(this->_major_storage[major_idx], minor_id);
193+
return std::views::iota(initial_id_v<id_type>, this->_major_storage.size())
194+
| std::views::filter([this, minor_id = id](id_type major_id) {
195+
return this->_contains(this->_major_storage[to_idx(major_id)], minor_id);
196196
});
197197
}
198198
}
@@ -487,10 +487,10 @@ class incidence_list<hgl::bf_directed_t, ImplTag> final {
487487
| std::views::join;
488488
}
489489
else { // get minor
490-
return std::views::iota(initial_id_v<size_type>, this->_tail_storage.size())
491-
| std::views::filter([this, minor_id = id](size_type major_idx) {
492-
return this->_contains(this->_tail_storage[major_idx], minor_id)
493-
or this->_contains(this->_head_storage[major_idx], minor_id);
490+
return std::views::iota(initial_id_v<id_type>, this->_tail_storage.size())
491+
| std::views::filter([this, minor_id = id](id_type major_id) {
492+
return this->_contains(this->_tail_storage[to_idx(major_id)], minor_id)
493+
or this->_contains(this->_head_storage[to_idx(major_id)], minor_id);
494494
});
495495
}
496496
}
@@ -502,11 +502,11 @@ class incidence_list<hgl::bf_directed_t, ImplTag> final {
502502
return std::views::all(std::invoke(storage_proj, this)[to_idx(id)]);
503503
}
504504
else { // get minor
505-
return std::views::iota(initial_id_v<size_type>, this->_tail_storage.size())
505+
return std::views::iota(initial_id_v<id_type>, this->_tail_storage.size())
506506
| std::views::filter(
507507
[this, &storage = std::invoke(storage_proj, this), minor_id = id](
508-
size_type major_idx
509-
) { return this->_contains(storage[major_idx], minor_id); }
508+
id_type major_id
509+
) { return this->_contains(storage[to_idx(major_id)], minor_id); }
510510
);
511511
}
512512
}

include/hgl/impl/incidence_matrix.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#pragma once
66

7+
#include "gl/types/core.hpp"
78
#include "hgl/constants.hpp"
89
#include "hgl/decl/impl_tags.hpp"
910
#include "hgl/directional_tags.hpp"
@@ -181,14 +182,13 @@ class incidence_matrix<hgl::undirected_t, ImplTag> final {
181182
template <element_type Element>
182183
gl_attr_force_inline auto _incident_with(const id_type id) const noexcept {
183184
if constexpr (Element == layout_tag::major_element) { // incident with major
184-
return std::views::iota(initial_id_v<size_type>, this->_matrix_row_size)
185-
| std::views::filter([&row = this->_matrix[to_idx(id)]](const size_type minor_idx
186-
) { return row[minor_idx]; });
185+
return std::views::iota(initial_id_v<id_type>, this->_matrix_row_size)
186+
| std::views::filter([&row = this->_matrix[to_idx(id)]](id_type minor_id) { return row[to_idx(minor_id)]; });
187187
}
188188
else { // incident with minor
189-
return std::views::iota(initial_id_v<size_type>, this->_matrix.size())
190-
| std::views::filter([this, minor_idx = to_idx(id)](const size_type major_idx) {
191-
return this->_matrix[major_idx][minor_idx];
189+
return std::views::iota(initial_id_v<id_type>, this->_matrix.size())
190+
| std::views::filter([this, minor_idx = to_idx(id)](id_type major_id) {
191+
return this->_matrix[to_idx(major_id)][minor_idx];
192192
});
193193
}
194194
}
@@ -479,16 +479,16 @@ class incidence_matrix<hgl::bf_directed_t, ImplTag> final {
479479
const id_type id, std::predicate<incidence_type> auto&& pred
480480
) const noexcept {
481481
if constexpr (Element == layout_tag::major_element) { // query major
482-
return std::views::iota(initial_id_v<size_type>, this->_matrix_row_size)
483-
| std::views::filter([&row = this->_matrix[to_idx(id)],
484-
pred](const size_type minor_idx) {
485-
return pred(row[minor_idx]);
482+
return std::views::iota(initial_id_v<id_type>, this->_matrix_row_size)
483+
| std::views::filter([&row = this->_matrix[to_idx(id)], pred](id_type minor_id) {
484+
return pred(row[to_idx(minor_id)]);
486485
});
487486
}
488487
else { // query minor
489-
return std::views::iota(initial_id_v<size_type>, this->_matrix.size())
490-
| std::views::filter([this, minor_idx = to_idx(id), pred](const size_type major_idx
491-
) { return pred(this->_matrix[major_idx][minor_idx]); });
488+
return std::views::iota(initial_id_v<id_type>, this->_matrix.size())
489+
| std::views::filter([this, minor_idx = to_idx(id), pred](id_type major_id) {
490+
return pred(this->_matrix[to_idx(major_id)][minor_idx]);
491+
});
492492
}
493493
}
494494

tests/CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(cpp-gl-test)
33

4-
# Set compile options
5-
if(NOT DEFINED CMAKE_CXX_FLAGS)
6-
set(
7-
CMAKE_CXX_FLAGS
8-
"-Werror -Wall -Wextra -Wcast-align -Wconversion -Wsign-conversion -Wunreachable-code -Wuninitialized -Wunused -pedantic -g -O2"
9-
CACHE STRING "Default C++ compile flags" FORCE
10-
)
11-
endif()
12-
134
# Common structure
145
set(SOURCE_DIRS "app")
156
set(INCLUDE_DIRS "include" "external")
@@ -33,7 +24,19 @@ function(add_test_target TARGET_NAME SOURCE_DIRS DATA_DIR TESTING_DEF)
3324
)
3425

3526
target_include_directories(${TARGET_NAME} PRIVATE ${INCLUDE_DIRS})
36-
target_compile_options(${TARGET_NAME} PRIVATE ${CMAKE_CXX_FLAGS})
27+
target_compile_options(${TARGET_NAME} PRIVATE
28+
-Werror
29+
-Wall
30+
-Wextra
31+
-Wcast-align
32+
-Wconversion
33+
-Wunreachable-code
34+
-Wuninitialized
35+
-Wunused
36+
-pedantic
37+
-g
38+
-O2
39+
)
3740
target_compile_definitions(${TARGET_NAME} PRIVATE
3841
${TESTING_DEF}
3942
TEST_DATA_PATH="${DATA_DIR}"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#if defined(__clang__) || defined(__GNUC__)
4+
5+
#define SUPPRESS_PRAGMA(x) _Pragma(#x)
6+
7+
#define SUPPRESS_WARNING_BEGIN(w) \
8+
SUPPRESS_PRAGMA(GCC diagnostic push) \
9+
SUPPRESS_PRAGMA(GCC diagnostic ignored w)
10+
11+
#define SUPPRESS_WARNING_END SUPPRESS_PRAGMA(GCC diagnostic pop)
12+
13+
#else
14+
15+
#define SUPPRESS_WARNING_BEGIN(w)
16+
#define SUPPRESS_WARNING_END
17+
18+
#endif

0 commit comments

Comments
 (0)