Skip to content

Commit

Permalink
Don't swap src and dst when returning edge iterators (#184)
Browse files Browse the repository at this point in the history
* Don't swap src and dst when returning edge iterators

* Remove ambiguous version of FindEdgeWithLabel
  • Loading branch information
aneeshdurg authored Apr 27, 2021
1 parent 38e0197 commit 5a8c284
Showing 1 changed file with 13 additions and 37 deletions.
50 changes: 13 additions & 37 deletions libgalois/include/katana/LC_CSR_CSC_Labeled_Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,22 +395,6 @@ class LC_CSR_CSC_Labeled_Graph
return FindFirstOrLastEdge<in_edges, opt>(begin, end, key);
}

/**
* Returns an edge iterator to an edge from src to dst with some label. If not
* found, returns nothing.
*/
std::optional<edge_iterator> FindEdgeWithLabel(
GraphNode src, GraphNode dst, const EdgeTy& data) const {
// trivial check; can't be connected if degree is 0
if (degrees_[src] == 0 || in_degrees_[dst] == 0) {
return std::nullopt;
}
if (degrees_[src] < in_degrees_[dst]) {
return FindEdgeWithLabel<false>(src, dst, data);
}
return FindEdgeWithLabel<true>(dst, src, data);
}

/**
* Returns an edge iterator to an edge with some node and key with some label
* by searching for the key via the node's outgoing or incoming edges.
Expand All @@ -433,35 +417,20 @@ class LC_CSR_CSC_Labeled_Graph
* nothing.
*/
std::optional<edges_iterator> FindAllEdgesWithLabel(
GraphNode src, GraphNode dst, const EdgeTy& data) const {
GraphNode node, GraphNode key, const EdgeTy& data) const {
// trivial check; can't be connected if degree is 0
if (degrees_[src] == 0 || in_degrees_[dst] == 0) {
if (degrees_[node] == 0 || in_degrees_[key] == 0) {
return std::nullopt;
}
if (degrees_[src] < in_degrees_[dst]) {
return FindAllEdgesWithLabel<false>(src, dst, data);
}

return FindAllEdgesWithLabel<true>(dst, src, data);
}

/**
* Returns all edges with some node and key with some label by searching for
* the key via the node's outgoing or incoming edges. If not found, returns
* nothing.
*/
template <bool in_edges>
std::optional<edges_iterator> FindAllEdgesWithLabel(
GraphNode node, GraphNode key, const EdgeTy& data) const {
auto first = FindFirstOrLastEdgeWithLabel<
in_edges, FindEdgeWithLabelOptions::FindFirst>(node, key, data);
false, FindEdgeWithLabelOptions::FindFirst>(node, key, data);
if (!first) {
return std::nullopt;
}

auto last =
FindFirstOrLastEdge<in_edges, FindEdgeWithLabelOptions::FindLast>(
std::get<1>(*first), std::get<2>(*first), key);
auto last = FindFirstOrLastEdge<false, FindEdgeWithLabelOptions::FindLast>(
std::get<1>(*first), std::get<2>(*first), key);
KATANA_LOG_DEBUG_ASSERT(last);

return internal::make_no_deref_range(
Expand Down Expand Up @@ -512,7 +481,14 @@ class LC_CSR_CSC_Labeled_Graph
*/
bool IsConnectedWithEdgeLabel(
GraphNode src, GraphNode dst, const EdgeTy& data) const {
return FindEdgeWithLabel(src, dst, data).has_value();
// trivial check; can't be connected if degree is 0
if (degrees_[src] == 0 || in_degrees_[dst] == 0) {
return false;
}
if (degrees_[src] < in_degrees_[dst]) {
return FindEdgeWithLabel<false>(src, dst, data).has_value();
}
return FindEdgeWithLabel<true>(dst, src, data).has_value();
}

/**
Expand Down

0 comments on commit 5a8c284

Please sign in to comment.