public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH GCC][01/06]New interface returning all adjacent vertices in graph
@ 2017-08-14 10:04 Bin Cheng
  2017-08-21 13:31 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Bin Cheng @ 2017-08-14 10:04 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-graphds-adjacent_vertices-20170801.txt.patch --]
[-- Type: text/x-patch; name="0001-graphds-adjacent_vertices-20170801.txt.patch", Size: 1509 bytes --]

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH GCC][01/06]New interface returning all adjacent vertices in graph
  2017-08-14 10:04 [PATCH GCC][01/06]New interface returning all adjacent vertices in graph Bin Cheng
@ 2017-08-21 13:31 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-08-21 13:31 UTC (permalink / raw)
  To: Bin Cheng; +Cc: gcc-patches, nd

On Mon, Aug 14, 2017 at 11:19 AM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> This simple patch adds new interface returning adjacent vertices for a vertex in graph.
> Bootstrap and test in series.  Is it OK?

The comment of the function doesn't match its implementation.  Why did
you choose
to use the dfs helpers instead of (more clearly IMHO) using

 e = v->succ;
 while (e)
   {
     adj->safe_push (e->dest);
     e = e->succ_next;

given you do not expose the direction as arggument to adjacent_vertices?  Btw,
is this "adjacent" a term understood in the context of (directed) graphs?

Richard.

> Thanks,
> bin
> 2017-08-10  Bin Cheng  <bin.cheng@arm.com>
>
>         * graphds.c (adjacent_vertices): New function.
>         * graphds.h (adjacent_vertices): New declaration.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-21 13:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-14 10:04 [PATCH GCC][01/06]New interface returning all adjacent vertices in graph Bin Cheng
2017-08-21 13:31 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).