in cpp/src/graphar/high-level/edges_builder.cc [29:83]
Status EdgesBuilder::Dump() {
// construct the writer
EdgeChunkWriter writer(edge_info_, prefix_, adj_list_type_, validate_level_);
// construct empty edge collections for vertex chunks without edges
IdType num_vertex_chunks =
(num_vertices_ + vertex_chunk_size_ - 1) / vertex_chunk_size_;
for (IdType i = 0; i < num_vertex_chunks; i++)
if (edges_.find(i) == edges_.end()) {
std::vector<Edge> empty_chunk_edges;
edges_[i] = empty_chunk_edges;
}
// dump the offsets
if (adj_list_type_ == AdjListType::ordered_by_source ||
adj_list_type_ == AdjListType::ordered_by_dest) {
for (auto& chunk_edges : edges_) {
IdType vertex_chunk_index = chunk_edges.first;
// sort the edges
if (adj_list_type_ == AdjListType::ordered_by_source)
sort(chunk_edges.second.begin(), chunk_edges.second.end(), cmp_src);
if (adj_list_type_ == AdjListType::ordered_by_dest)
sort(chunk_edges.second.begin(), chunk_edges.second.end(), cmp_dst);
// construct and write offset chunk
GAR_ASSIGN_OR_RAISE(
auto offset_table,
getOffsetTable(vertex_chunk_index, chunk_edges.second));
GAR_RETURN_NOT_OK(
writer.WriteOffsetChunk(offset_table, vertex_chunk_index));
}
}
// dump the vertex num
GAR_RETURN_NOT_OK(writer.WriteVerticesNum(num_vertices_));
// dump the edge nums
IdType vertex_chunk_num =
(num_vertices_ + vertex_chunk_size_ - 1) / vertex_chunk_size_;
for (IdType vertex_chunk_index = 0; vertex_chunk_index < vertex_chunk_num;
vertex_chunk_index++) {
if (edges_.find(vertex_chunk_index) == edges_.end()) {
GAR_RETURN_NOT_OK(writer.WriteEdgesNum(vertex_chunk_index, 0));
} else {
GAR_RETURN_NOT_OK(writer.WriteEdgesNum(
vertex_chunk_index, edges_[vertex_chunk_index].size()));
}
}
// dump the edges
for (auto& chunk_edges : edges_) {
IdType vertex_chunk_index = chunk_edges.first;
// convert to table
GAR_ASSIGN_OR_RAISE(auto input_table, convertToTable(chunk_edges.second));
// write table
GAR_RETURN_NOT_OK(writer.WriteTable(input_table, vertex_chunk_index, 0));
chunk_edges.second.clear();
}
is_saved_ = true;
return Status::OK();
}