Skip to content

Commit

Permalink
Rename edge_type to neighbor_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Laxman Dhulipala committed Dec 1, 2024
1 parent 93549d2 commit 3e2ebb5
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 65 deletions.
12 changes: 6 additions & 6 deletions benchmarks/CycleCounting/Parallel5Cycle/FiveCycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ inline ulong Count5CycleVertex(Graph& GDO, Graph2& DGDO, U_FastReset* V,
template <class Graph>
inline ulong Count5Cycle(Graph& GA, long order_type = 0, double epsilon = 0.1) {
using W = typename Graph::weight_type;
// using edge = typename Graph::edge_type; //std::tuple<uintE, W>;
// using edge = typename Graph::neighbor_type; //std::tuple<uintE, W>;
std::cout << "INFO: testing resetting U instead of reallocating (parallel "
"with scheduling)."
<< std::endl;
Expand Down Expand Up @@ -482,7 +482,7 @@ template <class Graph>
inline ulong Count5Cycle_serial(Graph& GA, long order_type = 0,
double epsilon = 0.1) {
using W = typename Graph::weight_type;
// using edge = typename Graph::edge_type; //std::tuple<uintE, W>;
// using edge = typename Graph::neighbor_type; //std::tuple<uintE, W>;

std::cout << "INFO: testing resetting U instead of reallocating."
<< std::endl;
Expand Down Expand Up @@ -540,7 +540,7 @@ template <class Graph>
inline ulong Count5Cycle_no_scheduling(Graph& GA, long order_type = 0,
double epsilon = 0.1) {
using W = typename Graph::weight_type;
// using edge = typename Graph::edge_type; //std::tuple<uintE, W>;
// using edge = typename Graph::neighbor_type; //std::tuple<uintE, W>;
std::cout << "INFO: testing resetting U instead of reallocating."
<< std::endl;

Expand Down Expand Up @@ -718,7 +718,7 @@ inline ulong Count5Cycle_ESCAPE(Graph& GA, long order_type = 0,
double epsilon = 0.1) {
// std::cout << "JUST TO MAKE SURE I AM REALLY USING ESCAPE" << std::endl;
using W = typename Graph::weight_type;
// using edge = typename Graph::edge_type; //std::tuple<uintE, W>;
// using edge = typename Graph::neighbor_type; //std::tuple<uintE, W>;

// auto GA2 = relabel_graph(GA, sequence<uintT>(GA.n, [&](size_t i){return
// i;}));
Expand Down Expand Up @@ -893,7 +893,7 @@ inline ulong Count5Cycle_ESCAPE_par(Graph& GA, long order_type = 0,
double epsilon = 0.1) {
// std::cout << "JUST TO MAKE SURE I AM REALLY USING ESCAPE" << std::endl;
using W = typename Graph::weight_type;
// using edge = typename Graph::edge_type; //std::tuple<uintE, W>;
// using edge = typename Graph::neighbor_type; //std::tuple<uintE, W>;

// auto GA2 = relabel_graph(GA, sequence<uintT>(GA.n, [&](size_t i){return
// i;}));
Expand Down Expand Up @@ -1096,4 +1096,4 @@ inline ulong Count5Cycle_ESCAPE_par(Graph& GA, long order_type = 0,
std::cout << "##### Actual counting: " << tt2 << std::endl;
return cycleCount;
}
} // namespace gbbs
} // namespace gbbs
2 changes: 1 addition & 1 deletion benchmarks/SCAN/IndexBased/intersect.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ typename IntersectReturn<Weight>::type intersect_f_with_index_par(
if
constexpr(
std::is_same<VertexTemplate<Weight>, symmetric_vertex<Weight>>::value) {
using Neighbor = typename VertexTemplate<Weight>::edge_type;
using Neighbor = typename VertexTemplate<Weight>::neighbor_type;
const auto seqA{
gbbs::make_slice<Neighbor>(A->neighbors, A->out_degree())};
const auto seqB{
Expand Down
1 change: 1 addition & 0 deletions gbbs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ cc_library(
":macros",
":vertex",
":vertex_subset",
"//gbbs/helpers:undirected_edge",
],
)

Expand Down
16 changes: 8 additions & 8 deletions gbbs/compressed_vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ struct compressed_neighbors {
template <class W, class C>
struct compressed_symmetric_vertex {
using vertex = compressed_symmetric_vertex<W, C>;
using edge_type = uchar;
using neighbor_type = uchar;

edge_type* neighbors;
neighbor_type* neighbors;
uintE degree;
uintE id;

compressed_symmetric_vertex(edge_type* n, vertex_data& vdata, uintE _id) {
compressed_symmetric_vertex(neighbor_type* n, vertex_data& vdata, uintE _id) {
neighbors = n + vdata.offset;
degree = vdata.degree;
id = _id;
Expand All @@ -290,16 +290,16 @@ struct compressed_symmetric_vertex {
template <class W, class C>
struct compressed_asymmetric_vertex {
using vertex = compressed_symmetric_vertex<W, C>;
using edge_type = uchar;
using neighbor_type = uchar;

edge_type* inNeighbors;
edge_type* outNeighbors;
neighbor_type* inNeighbors;
neighbor_type* outNeighbors;
uintE outDegree;
uintE inDegree;
uintE id;

compressed_asymmetric_vertex(edge_type* out_neighbors, vertex_data& out_data,
edge_type* in_neighbors, vertex_data& in_data,
compressed_asymmetric_vertex(neighbor_type* out_neighbors, vertex_data& out_data,
neighbor_type* in_neighbors, vertex_data& in_data,
uintE _id) {
inNeighbors = in_neighbors + in_data.offset;
outNeighbors = out_neighbors + out_data.offset;
Expand Down
48 changes: 25 additions & 23 deletions gbbs/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "flags.h"
#include "macros.h"
#include "vertex.h"
#include "gbbs/helpers/undirected_edge.h"

namespace gbbs {

Expand All @@ -44,16 +45,17 @@ namespace gbbs {
// 1) vertex_type: vertex template, parametrized by the weight type associated
// with each edge
// 2) W: the edge weight template
// The graph is represented as an array of edges of type
// vertex_type::edge_type.
// The graph is represented as an array of edges to neighbors of type
// vertex_type::neighbor_type.
// For uncompressed vertices, this type is equal to tuple<uintE, W>.
template <template <class W> class vertex_type, class W>
struct symmetric_graph {
using vertex = vertex_type<W>;
using weight_type = W;
using edge_type = typename vertex::edge_type;
using neighbor_type = typename vertex::neighbor_type;
using graph = symmetric_graph<vertex_type, W>;
using vertex_weight_type = double;
using edge = std::tuple<uintE, uintE, W>;

size_t num_vertices() const { return n; }
size_t num_edges() const { return m; }
Expand All @@ -75,7 +77,7 @@ struct symmetric_graph {

void zeroVertexDegree(uintE id) { decreaseVertexDegree(id, 0); }

sequence<std::tuple<uintE, uintE, W>> edges() const {
sequence<edge> edges() const {
using g_edge = std::tuple<uintE, uintE, W>;
auto degs = sequence<size_t>::from_function(
n, [&](size_t i) { return get_vertex(i).out_degree(); });
Expand Down Expand Up @@ -123,7 +125,7 @@ struct symmetric_graph {
deletion_fn([]() {}) {}

symmetric_graph(vertex_data* v_data, size_t n, size_t m,
std::function<void()>&& _deletion_fn, edge_type* _e0,
std::function<void()>&& _deletion_fn, neighbor_type* _e0,
vertex_weight_type* _vertex_weights = nullptr)
: v_data(v_data),
e0(_e0),
Expand Down Expand Up @@ -168,7 +170,7 @@ struct symmetric_graph {
n = other.n;
m = other.m;
v_data = gbbs::new_array_no_init<vertex_data>(n);
e0 = gbbs::new_array_no_init<edge_type>(m);
e0 = gbbs::new_array_no_init<neighbor_type>(m);
parallel_for(0, n, [&](size_t i) { v_data[i] = other.v_data[i]; });
parallel_for(0, m, [&](size_t i) { e0[i] = other.e0[i]; });
deletion_fn = [=]() {
Expand All @@ -193,7 +195,7 @@ struct symmetric_graph {
// Graph Data
vertex_data* v_data;
// Pointer to edges
edge_type* e0;
neighbor_type* e0;
// Pointer to vertex weights
vertex_weight_type* vertex_weights;

Expand All @@ -213,7 +215,7 @@ template <template <class W> class vertex_type, class W>
struct symmetric_ptr_graph {
using vertex = vertex_type<W>;
using weight_type = W;
using edge_type = typename vertex::edge_type;
using neighbor_type = typename vertex::neighbor_type;
using graph = symmetric_ptr_graph<vertex_type, W>;
using vertex_weight_type = double;

Expand Down Expand Up @@ -337,7 +339,7 @@ struct symmetric_ptr_graph {
});
offsets[n] = 0;
size_t total_space = parlay::scan_inplace(make_slice(offsets));
edge_type* E = gbbs::new_array_no_init<edge_type>(total_space);
neighbor_type* E = gbbs::new_array_no_init<neighbor_type>(total_space);

parallel_for(0, n, [&](size_t i) {
size_t offset = offsets[i];
Expand Down Expand Up @@ -400,13 +402,13 @@ struct symmetric_ptr_graph {
* 2) W: the edge weight template
*
* The graph is represented as an array of edges of type
* vertex_type::edge_type, which is just a pair<uintE, W>.
* vertex_type::neighbor_type, which is just a pair<uintE, W>.
* */
template <template <class W> class vertex_type, class W>
struct asymmetric_graph {
using vertex = vertex_type<W>;
using weight_type = W;
using edge_type = typename vertex::edge_type;
using neighbor_type = typename vertex::neighbor_type;
using vertex_weight_type = double;

// number of vertices in G
Expand All @@ -420,10 +422,10 @@ struct asymmetric_graph {
vertex_data* v_in_data;

// Pointer to out-edges
edge_type* out_edges;
neighbor_type* out_edges;

// Pointer to in-edges
edge_type* in_edges;
neighbor_type* in_edges;

// Pointer to vertex weights
vertex_weight_type* vertex_weights;
Expand All @@ -444,7 +446,7 @@ struct asymmetric_graph {

asymmetric_graph(vertex_data* v_out_data, vertex_data* v_in_data, size_t n,
size_t m, std::function<void()> _deletion_fn,
edge_type* _out_edges, edge_type* _in_edges,
neighbor_type* _out_edges, neighbor_type* _in_edges,
vertex_weight_type* _vertex_weights = nullptr)
: n(n),
m(m),
Expand Down Expand Up @@ -500,8 +502,8 @@ struct asymmetric_graph {
m = other.m;
v_out_data = gbbs::new_array_no_init<vertex_data>(n);
v_in_data = gbbs::new_array_no_init<vertex_data>(n);
out_edges = gbbs::new_array_no_init<edge_type>(m);
in_edges = gbbs::new_array_no_init<edge_type>(m);
out_edges = gbbs::new_array_no_init<neighbor_type>(m);
in_edges = gbbs::new_array_no_init<neighbor_type>(m);
parallel_for(0, n, [&](size_t i) { v_out_data[i] = other.v_out_data[i]; });
parallel_for(0, n, [&](size_t i) { v_in_data[i] = other.v_in_data[i]; });
parallel_for(0, m, [&](size_t i) { out_edges[i] = other.out_edges[i]; });
Expand Down Expand Up @@ -541,7 +543,7 @@ template <template <class W> class vertex_type, class W>
struct asymmetric_ptr_graph {
using vertex = vertex_type<W>;
using weight_type = W;
using edge_type = typename vertex::edge_type;
using neighbor_type = typename vertex::neighbor_type;
using vertex_weight_type = double;

// number of vertices in G
Expand Down Expand Up @@ -617,8 +619,8 @@ struct asymmetric_ptr_graph {

size_t in_space = parlay::scan_inplace(make_slice(in_offsets));
size_t out_space = parlay::scan_inplace(make_slice(out_offsets));
edge_type* inE = gbbs::new_array_no_init<edge_type>(in_space);
edge_type* outE = gbbs::new_array_no_init<edge_type>(out_space);
neighbor_type* inE = gbbs::new_array_no_init<neighbor_type>(in_space);
neighbor_type* outE = gbbs::new_array_no_init<neighbor_type>(out_space);

parallel_for(0, n, [&](size_t i) {
size_t out_offset = out_offsets[i];
Expand Down Expand Up @@ -690,7 +692,7 @@ static inline symmetric_graph<symmetric_vertex, Wgh> sym_graph_from_edges(
EdgeSeq& A, size_t n, GetU&& get_u, GetV&& get_v, GetW&& get_w,
bool is_sorted = false) {
using vertex = symmetric_vertex<Wgh>;
using edge_type = typename vertex::edge_type;
using neighbor_type = typename vertex::neighbor_type;
size_t m = A.size();

if (m == 0) {
Expand Down Expand Up @@ -747,7 +749,7 @@ static inline symmetric_graph<symmetric_vertex, Wgh> sym_graph_from_edges(
gbbs::free_array(v_data, n);
gbbs::free_array(edges, m);
},
(edge_type*)edges);
(neighbor_type*)edges);
}

template <class Wgh>
Expand Down Expand Up @@ -804,7 +806,7 @@ static inline asymmetric_graph<asymmetric_vertex, Wgh> asym_graph_from_edges(
EdgeSeq& A, size_t n, GetU&& get_u, GetV&& get_v, GetW&& get_w,
bool is_sorted = false) {
using vertex = asymmetric_vertex<Wgh>;
using edge_type = typename vertex::edge_type;
using neighbor_type = typename vertex::neighbor_type;
size_t m = A.size();

if (m == 0) {
Expand Down Expand Up @@ -874,7 +876,7 @@ static inline asymmetric_graph<asymmetric_vertex, Wgh> asym_graph_from_edges(
gbbs::free_array(in_edges, m);
gbbs::free_array(out_edges, m);
},
(edge_type*)out_edges, (edge_type*)in_edges);
(neighbor_type*)out_edges, (neighbor_type*)in_edges);
}

template <class Wgh>
Expand Down
14 changes: 7 additions & 7 deletions gbbs/graph_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ std::vector<Edge<gbbs::empty>> read_unweighted_edge_list(const char* filename);
template <class weight_type>
asymmetric_graph<asymmetric_vertex, weight_type> edge_list_to_asymmetric_graph(
const std::vector<Edge<weight_type>>& edge_list) {
using edge_type = typename asymmetric_vertex<weight_type>::edge_type;
using neighbor_type = typename asymmetric_vertex<weight_type>::neighbor_type;

if (edge_list.empty()) {
return asymmetric_graph<asymmetric_vertex, weight_type>{};
Expand All @@ -394,8 +394,8 @@ asymmetric_graph<asymmetric_vertex, weight_type> edge_list_to_asymmetric_graph(
vertex_data* vertex_in_data =
internal::sorted_edges_to_vertex_data_array(num_vertices, in_edges);

edge_type* out_edges_array = gbbs::new_array_no_init<edge_type>(num_edges);
edge_type* in_edges_array = gbbs::new_array_no_init<edge_type>(num_edges);
neighbor_type* out_edges_array = gbbs::new_array_no_init<neighbor_type>(num_edges);
neighbor_type* in_edges_array = gbbs::new_array_no_init<neighbor_type>(num_edges);
parallel_for(0, num_edges, [&](const size_t i) {
const Edge<weight_type>& out_edge = out_edges[i];
out_edges_array[i] = std::make_tuple(out_edge.to, out_edge.weight);
Expand Down Expand Up @@ -424,7 +424,7 @@ asymmetric_graph<asymmetric_vertex, weight_type> edge_list_to_asymmetric_graph(
template <class weight_type>
symmetric_graph<symmetric_vertex, weight_type> edge_list_to_symmetric_graph(
const std::vector<Edge<weight_type>>& edge_list) {
using edge_type = typename symmetric_vertex<weight_type>::edge_type;
using neighbor_type = typename symmetric_vertex<weight_type>::neighbor_type;

if (edge_list.empty()) {
return symmetric_graph<symmetric_vertex, weight_type>{};
Expand All @@ -444,7 +444,7 @@ symmetric_graph<symmetric_vertex, weight_type> edge_list_to_symmetric_graph(
vertex_data* vertex_data =
internal::sorted_edges_to_vertex_data_array(num_vertices, edges);

edge_type* edges_array = gbbs::new_array_no_init<edge_type>(num_edges);
neighbor_type* edges_array = gbbs::new_array_no_init<neighbor_type>(num_edges);
parallel_for(0, num_edges, [&](const size_t i) {
const Edge<weight_type>& edge = edges[i];
edges_array[i] = std::make_tuple(edge.to, edge.weight);
Expand All @@ -462,7 +462,7 @@ symmetric_graph<symmetric_vertex, weight_type> edge_list_to_symmetric_graph(
template <class weight_type>
symmetric_graph<symmetric_vertex, weight_type> edge_list_to_symmetric_graph(
const edge_array<weight_type>& edge_list) {
using edge_type = typename symmetric_vertex<weight_type>::edge_type;
using neighbor_type = typename symmetric_vertex<weight_type>::neighbor_type;
using Edge = gbbs_io::Edge<weight_type>;

if (edge_list.E.size() == 0) {
Expand All @@ -484,7 +484,7 @@ symmetric_graph<symmetric_vertex, weight_type> edge_list_to_symmetric_graph(
vertex_data* vertex_data =
internal::sorted_edges_to_vertex_data_array(num_vertices, edges);

edge_type* edges_array = gbbs::new_array_no_init<edge_type>(num_edges);
neighbor_type* edges_array = gbbs::new_array_no_init<neighbor_type>(num_edges);
parallel_for(0, num_edges, [&](const size_t i) {
const Edge& edge = edges[i];
edges_array[i] = std::make_tuple(edge.to, edge.weight);
Expand Down
2 changes: 1 addition & 1 deletion gbbs/graph_mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ template <
typename std::enable_if<std::is_same<vertex<W>, symmetric_vertex<W>>::value,
int>::type = 0>
inline std::tuple<size_t, size_t, vertex_data*,
typename symmetric_vertex<W>::edge_type*>
typename symmetric_vertex<W>::neighbor_type*>
filter_graph(Graph& G, P& pred) {
using w_vertex = vertex<W>;
size_t n = G.num_vertices();
Expand Down
Loading

0 comments on commit 3e2ebb5

Please sign in to comment.