Skip to content

Commit

Permalink
[FEAT][C++] Change the default namespace to graphar (#413)
Browse files Browse the repository at this point in the history
* [FEAT][C++] Change the default namespace to `graphar`

Signed-off-by: acezen <[email protected]>

* Fix the macro definition

Signed-off-by: acezen <[email protected]>

* Fix format

Signed-off-by: acezen <[email protected]>

---------

Signed-off-by: acezen <[email protected]>
  • Loading branch information
acezen authored Mar 26, 2024
1 parent 1592d34 commit f77897e
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 109 deletions.
4 changes: 2 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ project(graph-archive LANGUAGES C CXX VERSION ${GAR_VERSION})
# cmake options
# ------------------------------------------------------------------------------

option(NAMESPACE "User specific namespace, default if GraphArchive" OFF)
option(NAMESPACE "User specific namespace, default is graphar" OFF)
option(BUILD_TESTS "Build unit tests" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_BENCHMARKS "Build benchmarks" OFF)

if (NAMESPACE)
add_definitions(-DGAR_NAMESPACE=${NAMESPACE})
else()
add_definitions(-DGAR_NAMESPACE=GraphArchive)
add_definitions(-DGAR_NAMESPACE=graphar)
endif()
# ------------------------------------------------------------------------------
# setting default cmake type to Release
Expand Down
2 changes: 1 addition & 1 deletion cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Release build:
Build with a custom namespace:

The `namespace` is configurable. By default,
it is defined in `namespace GraphArchive`; however this can be toggled by
it is defined in `namespace graphar`; however this can be toggled by
setting `NAMESPACE` option with cmake:

```bash
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/high_level_writer_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void edges_builder() {
auto edge_info = GAR_NAMESPACE::EdgeInfo::Load(edge_meta).value();
auto vertex_count = 3;
GAR_NAMESPACE::builder::EdgesBuilder builder(
edge_info, "/tmp/", GraphArchive::AdjListType::ordered_by_dest,
edge_info, "/tmp/", GAR_NAMESPACE::AdjListType::ordered_by_dest,
vertex_count);

// set validate level
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gar/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Status;
* returns false. Sample usage:
*
* ```
* GraphArchive::Result<Foo> result = CalculateFoo();
* graphar::Result<Foo> result = CalculateFoo();
* if (!result.has_error()) {
* Foo foo = result.value();
* foo.DoSomethingCool();
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/gar/util/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#if defined(GAR_NAMESPACE)
#define GAR_NAMESPACE_INTERNAL GAR_NAMESPACE
#else
#define GAR_NAMESPACE_INTERNAL GraphArchive
#define GAR_NAMESPACE_INTERNAL graphar
#endif

#define GAR_EXPAND(x) x
Expand Down
3 changes: 1 addition & 2 deletions cpp/test/test_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ TEST_CASE("test_edges_builder") {
auto edge_info = EdgeInfo::Load(edge_meta).value();
auto vertices_num = 903;
auto maybe_builder = builder::EdgesBuilder::Make(
edge_info, "/tmp/", GraphArchive::AdjListType::ordered_by_dest,
vertices_num);
edge_info, "/tmp/", AdjListType::ordered_by_dest, vertices_num);
REQUIRE(!maybe_builder.has_error());
auto builder = maybe_builder.value();

Expand Down
20 changes: 10 additions & 10 deletions docs/cpp/examples/bgl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ The source code of CC based on BGL can be found at `bgl_example.cc`_. In this pr
.. code:: C++

std::string path = ... // the path of the graph information file
auto graph_info = GraphArchive::GraphInfo::Load(path).value();
auto graph_info = graphar::GraphInfo::Load(path).value();

And then, the vertex collection and the edge collection are established as the handles to access the graph data:

.. code:: C++

auto maybe_vertices = GraphArchive::VerticesCollection::Make(graph_info, "person");
auto maybe_vertices = graphar::VerticesCollection::Make(graph_info, "person");
auto vertices = maybe_vertices.value();
auto maybe_edges = GraphArchive::EdgesCollection::Make(graph_info, "person", "knows", "person", GraphArchive::AdjListType::ordered_by_source);
auto maybe_edges = graphar::EdgesCollection::Make(graph_info, "person", "knows", "person", graphar::AdjListType::ordered_by_source);
auto edges = maybe_edges.value();

Next, we construct the in-memory graph data structure for BGL by traversing the vertices and edges via GraphAr's high-level reading interface (the vertex iterator and the edge iterator):
Expand All @@ -35,7 +35,7 @@ Next, we construct the in-memory graph data structure for BGL by traversing the
typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;

// declare a graph object with (num_vertices) vertices and an edge iterator
std::vector<std::pair<GraphArchive::IdType, GraphArchive::IdType>> edges_array;
std::vector<std::pair<graphar::IdType, graphar::IdType>> edges_array;
auto it_begin = edges->begin(), it_end = edges->end();
for (auto it = it_begin; it != it_end; ++it)
edges_array.push_back(std::make_pair(it.source(), it.destination()));
Expand Down Expand Up @@ -64,14 +64,14 @@ Finally, we could use a **VerticesBuilder** of GraphAr to write the results to n
.. code:: C++

// construct a new property group
GraphArchive::Property cc = {"cc", GraphArchive::int32(), false};
std::vector<GraphArchive::Property> property_vector = {cc};
auto group = GraphArchive::CreatePropertyGroup(property_vector, GraphArchive::FileType::PARQUET);
graphar::Property cc = {"cc", graphar::int32(), false};
std::vector<graphar::Property> property_vector = {cc};
auto group = graphar::CreatePropertyGroup(property_vector, graphar::FileType::PARQUET);

// construct the new vertex info
std::string vertex_label = "cc_result", vertex_prefix = "result/";
int chunk_size = 100;
auto new_info = GraphArchive::CreateVertexInfo(vertex_label, chunk_size, {group}, vertex_prefix);
auto new_info = graphar::CreateVertexInfo(vertex_label, chunk_size, {group}, vertex_prefix);

// access the vertices via the index map and vertex iterator of BGL
typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap;
Expand All @@ -80,10 +80,10 @@ Finally, we could use a **VerticesBuilder** of GraphAr to write the results to n
std::pair<vertex_iter, vertex_iter> vp;

// dump the results through the VerticesBuilder
GraphArchive::builder::VerticesBuilder builder(new_info, "/tmp/");
graphar::builder::VerticesBuilder builder(new_info, "/tmp/");
for (vp = boost::vertices(g); vp.first!= vp.second; ++vp.first) {
Vertex v = *vp.first;
GraphArchive::builder::Vertex vertex(index[v]);
graphar::builder::Vertex vertex(index[v]);
vertex.AddProperty(cc.name, component[index[v]]);
builder.AddVertex(vertex);
}
Expand Down
14 changes: 7 additions & 7 deletions docs/cpp/examples/out-of-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ This algorithm can be implemented based on streaming the edges via GraphAr's rea
auto it_begin = edges->begin(), it_end = edges->end();

// initialize for all vertices
std::vector<GraphArchive::IdType> component(num_vertices);
for (GraphArchive::IdType i = 0; i < num_vertices; i++)
std::vector<graphar::IdType> component(num_vertices);
for (graphar::IdType i = 0; i < num_vertices; i++)
component[i] = i;

// stream all edges for each iteration
for (int iter = 0; ; iter++) {
bool flag = false;
for (auto it = it_begin; it != it_end; ++it) {
GraphArchive::IdType src = it.source(), dst = it.destination();
graphar::IdType src = it.source(), dst = it.destination();
// update
if (component[src] < component[dst]) {
component[dst] = component[src];
Expand Down Expand Up @@ -76,16 +76,16 @@ An out-of-core BFS algorithm could be implemented based on streaming the graph d
auto it_begin = edges->begin(), it_end = edges->end();

// initialize for all vertices
GraphArchive::IdType root = 0; // the BFS root
graphar::IdType root = 0; // the BFS root
std::vector<int32_t> distance(num_vertices);
for (GraphArchive::IdType i = 0; i < num_vertices; i++)
for (graphar::IdType i = 0; i < num_vertices; i++)
distance[i] = (i == root ? 0 : -1);

// stream all edges for each iteration
for (int iter = 0; ; iter++) {
GraphArchive::IdType count = 0;
graphar::IdType count = 0;
for (auto it = it_begin; it != it_end; ++it) {
GraphArchive::IdType src = it.source(), dst = it.destination();
graphar::IdType src = it.source(), dst = it.destination();
// update
if (distance[src] == iter && distance[dst] == -1) {
distance[dst] = distance[src] + 1;
Expand Down
14 changes: 7 additions & 7 deletions docs/cpp/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Also, the metadata of a graph can be constructed easily through reading the alre

// construct graph information from file
std::string path = ... // the path of the graph information file (e.g., ldbc_sample.graph.yml)
auto graph_info = GraphArchive::GraphInfo::Load(path).value();
auto graph_info = graphar::GraphInfo::Load(path).value();

// get vertex information
auto vertex_info = graph_info->GetVertexInfo("person");
Expand All @@ -103,7 +103,7 @@ As a simple case, the following example shows how to read all vertices with labe
.. code:: C++

graph_info = ...
auto vertices = GraphArchive::VerticesCollection::Make(graph_info, "person").value();
auto vertices = graphar::VerticesCollection::Make(graph_info, "person").value();

for (auto it = vertices->begin(); it != vertices->end(); ++it) {
// get a vertex and access its data
Expand All @@ -116,7 +116,7 @@ The next example reads all edges with label "person_knows_person" from the above
.. code:: C++

graph_info = ...
auto expect = GraphArchive::EdgesCollection::Make(graph_info, "person", "konws", "person", GraphArchive::AdjListType::ordered_by_source);
auto expect = graphar::EdgesCollection::Make(graph_info, "person", "konws", "person", graphar::AdjListType::ordered_by_source);
auto edges = expect.value();

for (auto it = edges->begin(); it != edges->end(); ++it) {
Expand All @@ -137,10 +137,10 @@ As the simplest cases, the fist example below adds vertices to **VerticesBuilder

vertex_info = ...
prefix = ...
GraphArchive::builder::VerticesBuilder builder(vertex_info, prefix);
graphar::builder::VerticesBuilder builder(vertex_info, prefix);

// add a vertex
GraphArchive::builder::Vertex v;
graphar::builder::Vertex v;
v.AddProperty("id", 933);
v.AddProperty("firstName", "Alice");
builder.AddVertex(v);
Expand All @@ -155,10 +155,10 @@ As the simplest cases, the fist example below adds vertices to **VerticesBuilder
edge_info = ...
prefix = ...
vertices_num = ...
GraphArchive::builder::EdgesBuilder builder(edge_info, prefix, GraphArchive::AdjListType::ordered_by_source, vertices_num);
graphar::builder::EdgesBuilder builder(edge_info, prefix, graphar::AdjListType::ordered_by_source, vertices_num);

// add an edge (0 -> 3)
GraphArchive::builder::Edge e(0, 3);
graphar::builder::Edge e(0, 3);
e.AddProperty("creationDate", "2011-07-20T20:02:04.233+0000");
builder.AddEdge(e);
// add other edges
Expand Down
Loading

0 comments on commit f77897e

Please sign in to comment.