Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
build:
name: "${{ matrix.os }} (${{ matrix.compiler }})"
runs-on: ${{ matrix.runner }}
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
Comment thread
IanChenUIUC marked this conversation as resolved.
Outdated
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion include/networkit/graph/EdgeIterators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class EdgeTypeRange {
public:
EdgeTypeRange(const GraphType &G) : G(&G) {}

EdgeTypeRange() : G(nullptr){};
EdgeTypeRange() : G(nullptr) {};

~EdgeTypeRange() = default;

Expand Down
46 changes: 25 additions & 21 deletions include/networkit/graph/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ class Graph {
* @brief Virtual method for forInEdgesOf - overridden by GraphW for vector-based iteration
*/
virtual void
forInEdgesVirtualImpl(node u, bool directed, bool weighted, bool hasEdgeIds,
std::function<void(node, node, edgeweight, edgeid)> handle) const;
forInEdgesOfVirtualImpl(node u, bool directed, bool weighted, bool hasEdgeIds,
std::function<void(node, node, edgeweight, edgeid)> handle) const;

/**
* @brief Virtual method for parallelSumForEdges - overridden by GraphW for vector-based
Expand Down Expand Up @@ -933,7 +933,7 @@ class Graph {
* @return @c true if @a v exists, @c false otherwise.
*/

bool hasNode(node v) const noexcept { return (v < z) && this->exists[v]; }
virtual bool hasNode(node v) const noexcept { return (v < z) && this->exists[v]; }

/**
* Check if edge (u, v) exists in the graph.
Expand All @@ -942,7 +942,7 @@ class Graph {
* @param v Second endpoint of edge.
* @return @c true if edge exists, @c false otherwise.
*/
bool hasEdge(node u, node v) const;
virtual bool hasEdge(node u, node v) const;

/**
* @brief Virtual method for hasEdge - overridden by GraphW for vector-based graphs
Expand Down Expand Up @@ -1007,7 +1007,7 @@ class Graph {
*
* @return Weighted degree of @a u.
*/
edgeweight weightedDegree(node u, bool countSelfLoopsTwice = false) const;
virtual edgeweight weightedDegree(node u, bool countSelfLoopsTwice = false) const;

/**
* Returns the weighted in-degree of @a u.
Expand All @@ -1017,7 +1017,7 @@ class Graph {
*
* @return Weighted in-degree of @a v.
*/
edgeweight weightedDegreeIn(node u, bool countSelfLoopsTwice = false) const;
virtual edgeweight weightedDegreeIn(node u, bool countSelfLoopsTwice = false) const;

/**
* Returns <code>true</code> if this graph supports edge weights other
Expand Down Expand Up @@ -1198,7 +1198,7 @@ class Graph {
* @return Iterator range over the neighbors of @a u.
*/
NeighborRange<false> neighborRange(node u) const {
assert(exists[u]);
assert(hasNode(u));
return NeighborRange<false>(*this, u);
}

Expand All @@ -1212,7 +1212,7 @@ class Graph {
*/
NeighborWeightRange<false> weightNeighborRange(node u) const {
assert(isWeighted());
assert(exists[u]);
assert(hasNode(u));
return NeighborWeightRange<false>(*this, u);
}

Expand All @@ -1224,7 +1224,7 @@ class Graph {
*/
NeighborRange<true> inNeighborRange(node u) const {
assert(isDirected());
assert(exists[u]);
assert(hasNode(u));
return NeighborRange<true>(*this, u);
}

Expand All @@ -1238,7 +1238,7 @@ class Graph {
*/
NeighborWeightRange<true> weightInNeighborRange(node u) const {
assert(isDirected() && isWeighted());
assert(exists[u]);
assert(hasNode(u));
return NeighborWeightRange<true>(*this, u);
}

Expand Down Expand Up @@ -1473,7 +1473,7 @@ class Graph {
template <typename L>
void Graph::forNodes(L handle) const {
for (node v = 0; v < z; ++v) {
if (exists[v]) {
if (hasNode(v)) {
handle(v);
}
}
Expand All @@ -1491,7 +1491,7 @@ void Graph::parallelForNodes(L handle) const {
// For mutable graphs, check exists
#pragma omp parallel for
for (omp_index v = 0; v < static_cast<omp_index>(z); ++v) {
if (exists[v]) {
if (hasNode(v)) {
handle(v);
}
}
Expand All @@ -1501,7 +1501,7 @@ void Graph::parallelForNodes(L handle) const {
template <typename C, typename L>
void Graph::forNodesWhile(C condition, L handle) const {
for (node v = 0; v < z; ++v) {
if (exists[v]) {
if (hasNode(v)) {
if (!condition()) {
break;
}
Expand Down Expand Up @@ -1534,7 +1534,7 @@ void Graph::balancedParallelForNodes(L handle) const {
// For mutable graphs, check exists
#pragma omp parallel for schedule(guided)
for (omp_index v = 0; v < static_cast<omp_index>(z); ++v) {
if (exists[v]) {
if (hasNode(v)) {
handle(v);
}
}
Expand All @@ -1544,9 +1544,9 @@ void Graph::balancedParallelForNodes(L handle) const {
template <typename L>
void Graph::forNodePairs(L handle) const {
for (node u = 0; u < z; ++u) {
if (exists[u]) {
if (hasNode(u)) {
for (node v = u + 1; v < z; ++v) {
if (exists[v]) {
if (hasNode(v)) {
handle(u, v);
}
}
Expand All @@ -1568,9 +1568,9 @@ void Graph::parallelForNodePairs(L handle) const {
// For mutable graphs, check exists
#pragma omp parallel for schedule(guided)
for (omp_index u = 0; u < static_cast<omp_index>(z); ++u) {
if (exists[u]) {
if (hasNode(u)) {
for (node v = u + 1; v < z; ++v) {
if (exists[v]) {
if (hasNode(v)) {
handle(u, v);
}
}
Expand Down Expand Up @@ -1678,7 +1678,7 @@ inline void Graph::forOutEdgesOfImpl(node u, L handle) const {
} else {
// Vector-based graphs should use GraphW
// Check exists for mutable graphs
if (!exists[u])
if (!hasNode(u))
return;
throw std::runtime_error("forOutEdgesOfImpl not supported for vector-based graphs in base "
"Graph class - use GraphW");
Expand Down Expand Up @@ -1732,12 +1732,12 @@ inline void Graph::forInEdgesOfImpl(node u, L handle) const {
} else {
// For vector-based graphs (GraphW), use the virtual dispatch
// Check exists for mutable graphs
if (!exists[u])
if (!hasNode(u))
return;
// GraphW's forInEdgesVirtualImpl calls handle(v, u, ...) where v is neighbor and u is
// current node We need to swap so that edgeLambda receives (current, neighbor, ...) and
// passes neighbor to f
forInEdgesVirtualImpl(
forInEdgesOfVirtualImpl(
u, graphIsDirected, hasWeights, graphHasEdgeIds,
[&](node v, node u, edgeweight w, edgeid e) { edgeLambda(handle, u, v, w, e); });
}
Expand Down Expand Up @@ -1936,6 +1936,10 @@ void Graph::forEdgesOf(node u, L handle) const {
}
}
} else {
// For vector-based graphs (GraphW), use the virtual dispatch
// Check exists for mutable graphs
if (!hasNode(u))
return;
// For vector-based graphs, use virtual dispatch
forEdgesOfVirtualImpl(u, directed, weighted, edgesIndexed,
[&](node uu, node vv, edgeweight ww, edgeid ee) {
Expand Down
6 changes: 3 additions & 3 deletions include/networkit/graph/GraphW.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ class GraphW final : public Graph {
/**
* @brief Override for vector-based forInEdgesOf
*/
void forInEdgesVirtualImpl(
void forInEdgesOfVirtualImpl(
node u, bool directed, bool weighted, bool hasEdgeIds,
std::function<void(node, node, edgeweight, edgeid)> handle) const override;

Expand Down Expand Up @@ -999,7 +999,7 @@ class GraphW final : public Graph {
public:
NeighborRange(const GraphW &G, node u) : G(&G), u(u) { assert(G.hasNode(u)); };

NeighborRange() : G(nullptr){};
NeighborRange() : G(nullptr) {};

NeighborIterator begin() const {
assert(G);
Expand Down Expand Up @@ -1037,7 +1037,7 @@ class GraphW final : public Graph {
public:
NeighborWeightRange(const GraphW &G, node u) : G(&G), u(u) { assert(G.hasNode(u)); };

NeighborWeightRange() : G(nullptr){};
NeighborWeightRange() : G(nullptr) {};

NeighborWeightIterator begin() const {
assert(G);
Expand Down
Loading
Loading