Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add findEdge to LS_CSR #23

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 28 additions & 7 deletions libgalois/include/galois/graphs/LS_LC_CSR_Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ class LS_LC_CSR_Graph : private boost::noncopyable {
vertex_meta.end = vertex_meta.begin + vertex_meta.degree;
}

/*
* Returns whether the given edge exists.
*
* Assumes sortEdges was already called for the vertex!
*/
bool findEdgeSorted(VertexTopologyID src, VertexTopologyID dst) {
auto const& vertex_meta = m_vertices[src];
EdgeMetadata* start =
&getEdgeMetadata(vertex_meta.buffer, vertex_meta.begin);
EdgeMetadata* end = &getEdgeMetadata(vertex_meta.buffer, vertex_meta.end);

return std::binary_search(start, end, EdgeMetadata(dst));
}

void addEdges(VertexTopologyID src, const std::vector<VertexTopologyID> dsts,
std::vector<EdgeData> data) {
GALOIS_ASSERT(data.size() == dsts.size());
Expand Down Expand Up @@ -295,9 +309,7 @@ class LS_LC_CSR_Graph : private boost::noncopyable {

// insert new edges
std::transform(dsts.begin(), dsts.end(), &getEdgeMetadata(1, new_begin),
[](VertexTopologyID dst) {
return EdgeMetadata{.flags = 0, .dst = dst};
});
[](VertexTopologyID dst) { return EdgeMetadata(dst); });

// copy old, non-tombstoned edges
std::copy_if(&getEdgeMetadata(vertex_meta.buffer, vertex_meta.begin),
Expand Down Expand Up @@ -453,13 +465,22 @@ class LS_LC_CSR_Graph : private boost::noncopyable {
bool is_tomb() const noexcept { return (flags & TOMB) > 0; }
void set_tomb() { flags |= TOMB; }

bool operator<(EdgeMetadata const& rhs) {
if (is_tomb() != rhs.is_tomb())
EdgeMetadata() {}
explicit EdgeMetadata(VertexTopologyID dst) : flags(0), dst(dst) {}

// Sort edges, with tombstoned coming after non-tombstoned.
friend bool operator<(EdgeMetadata const& lhs, EdgeMetadata const& rhs) {
if (lhs.is_tomb() != rhs.is_tomb())
// tombstoned edges come last
return is_tomb() < rhs.is_tomb();
return lhs.is_tomb() < rhs.is_tomb();
else
// otherwise, sort by dst
return dst < rhs.dst;
return lhs.dst < rhs.dst;
}

// Check dst equality only.
friend bool operator==(EdgeMetadata const& lhs, EdgeMetadata const& rhs) {
return (lhs.dst == rhs.dst);
}

} __attribute__((packed));
Expand Down
2 changes: 1 addition & 1 deletion libgalois/include/galois/graphs/MorphGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ public
//! Sorts edge of a node by destination.
void sortEdgesByDst(GraphNode N,
galois::MethodFlag mflag = MethodFlag::WRITE) {
// acquire(N, mflag);
acquire(N, mflag);
typedef typename gNode::EdgeInfo EdgeInfo;
std::sort(N->begin(), N->end(),
[=](const EdgeInfo& e1, const EdgeInfo& e2) {
Expand Down
6 changes: 6 additions & 0 deletions libgalois/test/graph-compile-lscsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ int main() {
GALOIS_ASSERT(g.getEdgeDst(*(++(++g.edge_begin(eight)))) == 3);
GALOIS_ASSERT(g.getEdgeDst(*(--g.edge_end(eight))) == 3);

// check searching
GALOIS_ASSERT(g.findEdgeSorted(eight, 0));
GALOIS_ASSERT(!g.findEdgeSorted(eight, 1));
GALOIS_ASSERT(g.findEdgeSorted(eight, 2));
GALOIS_ASSERT(g.findEdgeSorted(eight, 3));

// check prefix sum
GALOIS_ASSERT(g[0] == 3);
GALOIS_ASSERT(g[1] == 3);
Expand Down