This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH GCC][01/06]New interface returning all adjacent vertices in graph


Hi,
This simple patch adds new interface returning adjacent vertices for a vertex in graph.
Bootstrap and test in series.  Is it OK?

Thanks,
bin
2017-08-10  Bin Cheng  <bin.cheng@arm.com>

	* graphds.c (adjacent_vertices): New function.
	* graphds.h (adjacent_vertices): New declaration.
From d84e4dd5b840d5f34a619a0f89e502fccf24326f Mon Sep 17 00:00:00 2001
From: Bin Cheng <binche01@e108451-lin.cambridge.arm.com>
Date: Tue, 13 Jun 2017 15:51:54 +0100
Subject: [PATCH 1/6] graphds-adjacent_vertices-20170801.txt

---
 gcc/graphds.c | 19 +++++++++++++++++++
 gcc/graphds.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/gcc/graphds.c b/gcc/graphds.c
index 2951349..5618074 100644
--- a/gcc/graphds.c
+++ b/gcc/graphds.c
@@ -338,6 +338,25 @@ for_each_edge (struct graph *g, graphds_edge_callback callback, void *data)
       callback (g, e, data);
 }
 
+/* Given graph G, record V's adjacent vertices in ADJ and return if ADJ
+   isn't NULL.  */
+
+void
+adjacent_vertices (struct graph *g, int v, vec<int> *adj)
+{
+  struct graph_edge *e;
+
+  if (!adj)
+    return;
+
+  e = dfs_fst_edge (g, v, true, NULL, NULL);
+  while (e != NULL)
+    {
+      adj->safe_push (e->dest);
+      e = dfs_next_edge (e, true, NULL, NULL);
+    }
+}
+
 /* Releases the memory occupied by G.  */
 
 void
diff --git a/gcc/graphds.h b/gcc/graphds.h
index 9f9fc10..86172a2 100644
--- a/gcc/graphds.h
+++ b/gcc/graphds.h
@@ -63,6 +63,7 @@ void graphds_domtree (struct graph *, int, int *, int *, int *);
 typedef void (*graphds_edge_callback) (struct graph *,
 				       struct graph_edge *, void *);
 void for_each_edge (struct graph *, graphds_edge_callback, void *);
+void adjacent_vertices (struct graph *, int, vec<int> *);
 void free_graph (struct graph *g);
 
 #endif /* GCC_GRAPHDS_H */
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]