Skip to content

Commit c690fd2

Browse files
authored
Merge pull request #161 from akrzemi1/cg
Fix bug in compressed_graph
2 parents e219048 + 6293979 commit c690fd2

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

include/graph/algorithm/connected_components.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "graph/views/breadth_first_search.hpp"
2222
#include <stack>
2323
#include <random>
24+
#include <numeric>
2425

2526
#ifndef GRAPH_CC_HPP
2627
# define GRAPH_CC_HPP

include/graph/container/compressed_graph.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ class csr_row_values {
171171
//requires views::copyable_vertex<invoke_result_t<VProj, range_value_t<VRng>>, VId, VV>
172172
constexpr void load_row_values(const VRng& vrng, VProj projection, size_type vertex_count) {
173173
if constexpr (sized_range<VRng>)
174-
vertex_count = max(vertex_count, size(vrng));
175-
resize(size(vrng));
174+
vertex_count = max(vertex_count, std::ranges::size(vrng));
175+
resize(std::ranges::size(vrng));
176176

177177
for (auto&& vtx : vrng) {
178178
const auto& [id, value] = projection(vtx);
@@ -745,14 +745,11 @@ class compressed_graph_base
745745
* @param vrng Input vertex range
746746
* @param eprojection Edge projection function object
747747
* @param vprojection Vertex projection function object
748-
* @param partition_start_ids Range of starting vertex ids for each partition. If empty, all vertices are in partition 0.
749748
*/
750749
template <forward_range ERng,
751750
forward_range VRng,
752-
forward_range PartRng,
753751
class EProj = identity,
754752
class VProj = identity>
755-
requires convertible_to<range_value_t<PartRng>, VId>
756753
//requires views::copyable_edge<invoke_result_t<EProj, range_value_t<ERng>>, VId, EV> &&
757754
// views::copyable_vertex<invoke_result_t<VProj, range_value_t<VRng>>, VId, VV>
758755
constexpr void load(const ERng& erng, const VRng& vrng, EProj eprojection = {}, VProj vprojection = {}) {

include/graph/container/container_utility.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ constexpr auto push_or_insert(C& container) {
8282
template <class C, class K>
8383
requires has_array_operator<C, K>
8484
constexpr auto assign_or_insert(C& container) {
85-
if constexpr (random_access_range<C>) {
86-
static_assert(sized_range<C>, "random_access container is assumed to have size()");
85+
if constexpr (::std::ranges::random_access_range<C>) {
86+
static_assert(::std::ranges::sized_range<C>, "random_access container is assumed to have size()");
8787
return [&container](const K& id, typename C::value_type&& value) {
8888
typename C::size_type k = static_cast<typename C::size_type>(id);
8989
assert(k < container.size());
@@ -99,8 +99,8 @@ constexpr auto assign_or_insert(C& container) {
9999
// ERng is a forward_range because it is traversed twice; once to get the max vertex_id
100100
// and a second time to load the edges.
101101
template <class ERng, class EIdFnc, class EValueFnc>
102-
concept edge_value_extractor = forward_range<ERng> && invocable<EIdFnc, typename ERng::value_type> &&
103-
invocable<EValueFnc, typename ERng::value_type>;
102+
concept edge_value_extractor = std::ranges::forward_range<ERng> && ::std::invocable<EIdFnc, typename ERng::value_type> &&
103+
::std::invocable<EValueFnc, typename ERng::value_type>;
104104

105105
namespace detail {
106106
//--------------------------------------------------------------------------------------

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(UNITTEST_SOURCES
6262

6363
"descriptor_tests.cpp"
6464
"tests.cpp"
65+
"compressed_graph_tests.cpp"
6566
)
6667

6768
foreach(SOURCE IN LISTS UNITTEST_SOURCES)

tests/compressed_graph_tests.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 Andrzej Krzemienski.
2+
//
3+
// Use, modification, and distribution is subject to the Boost Software
4+
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <catch2/catch_test_macros.hpp>
8+
#include <catch2/catch_template_test_macros.hpp>
9+
#include "graph/container/compressed_graph.hpp"
10+
#include <string>
11+
#include <vector>
12+
13+
// A
14+
// 0.8 / \ 0.4
15+
// B C
16+
// 0.1 \ / 0.2
17+
// D
18+
19+
const std::vector<graph::copyable_edge_t<unsigned, double>> ve {
20+
{0, 1, 0.8}, {0, 2, 0.4}, {1, 3, 0.1}, {2, 3, 0.2}
21+
};
22+
23+
const std::vector<graph::copyable_vertex_t<unsigned, std::string>> vv {
24+
{0, "A"}, {1, "B"}, {2, "C"}, {3, "D"}
25+
};
26+
27+
TEST_CASE("compressed_graph constructor", "[compressed_graph]") {
28+
using graph_t = graph::container::compressed_graph<double, std::string>;
29+
const graph_t g(ve, vv);
30+
31+
std::vector<std::string> vertex_names;
32+
33+
for (graph_t::vertex_type const& u : vertices(g))
34+
vertex_names.push_back(vertex_value(g, u));
35+
36+
REQUIRE(vertex_names == std::vector<std::string>{"A", "B", "C", "D"});
37+
}
38+

0 commit comments

Comments
 (0)