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

[Improvement][C++] Implement the add operator for VertexIter #128

Merged
merged 1 commit into from
Mar 31, 2023
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
7 changes: 7 additions & 0 deletions cpp/include/gar/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ class VertexIter {
return ret;
}

/** The add operator. */
VertexIter operator+(IdType offset) {
VertexIter ret(*this);
ret.cur_offset_ += offset;
return ret;
}

/** The equality operator. */
bool operator==(const VertexIter& rhs) const noexcept {
return cur_offset_ == rhs.cur_offset_;
Expand Down
7 changes: 7 additions & 0 deletions cpp/test/test_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ TEST_CASE("test_vertices_collection") {
GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label);
REQUIRE(!maybe_vertices_collection.has_error());
auto& vertices = maybe_vertices_collection.value();
auto count = 0;
for (auto it = vertices.begin(); it != vertices.end(); ++it) {
// access data through iterator directly
std::cout << it.id() << ", id=" << it.property<int64_t>("id").value()
Expand All @@ -48,7 +49,13 @@ TEST_CASE("test_vertices_collection") {
<< ", id=" << vertex.property<int64_t>("id").value()
<< ", firstName="
<< vertex.property<std::string>("firstName").value() << std::endl;
count++;
}
auto it_last = vertices.begin() + (count - 1);
std::cout << it_last.id()
<< ", id=" << it_last.property<int64_t>("id").value()
<< ", firstName="
<< it_last.property<std::string>("firstName").value() << std::endl;
}

TEST_CASE("test_edges_collection", "[Slow]") {
Expand Down