]> git.ozlabs.org Git - ccan/blobdiff - ccan/aga/aga.h
tcon: Encode information on container members in "type" canaries
[ccan] / ccan / aga / aga.h
index d5cc434b50ccb33ee0d5c3f7204d67ffeeb76cfa..28fa539947146965068cbc3d19b37cc0a75f2d36 100644 (file)
  *
  * - Errors are cleared on aga_finish().
  */
-
 #include "config.h"
 #include <string.h>
 
 #include <ccan/build_assert/build_assert.h>
 #include <ccan/check_type/check_type.h>
+#include <ccan/lstack/lstack.h>
+#include <ccan/lqueue/lqueue.h>
 
 struct aga_graph;
 struct aga_node;
@@ -140,7 +141,14 @@ typedef int (*aga_edge_info_fn)(const struct aga_graph *g,
 struct aga_node {
        int sequence;
        union {
-               /* Per-algorithm state here */
+               struct {
+                       struct lstack_link parent;
+                       const void *edge;
+               } dfs;
+               struct {
+                       struct lqueue_link next;
+                       const void *edge;
+               } bfs;
        } u;
 };
 
@@ -202,4 +210,25 @@ int aga_edge_info(const struct aga_graph *g, const struct aga_node *n,
             (_e) = aga_next_edge((_g), (_n), (_e)))                    \
                if ((_ei).to)
 
+/*
+ * Depth first search
+ */
+
+int aga_dfs_start(struct aga_graph *g);
+struct aga_node *aga_dfs_explore(struct aga_graph *g, struct aga_node *n);
+
+#define aga_dfs(_n, _g, _start)                                        \
+       for ((_n) = (_start); ((_n) = aga_dfs_explore((_g), (_n))) != NULL; )
+
+
+/*
+ * Breadth first search
+ */
+
+int aga_bfs_start(struct aga_graph *g);
+struct aga_node *aga_bfs_explore(struct aga_graph *g, struct aga_node *n);
+
+#define aga_bfs(_n, _g, _start)                                        \
+       for ((_n) = (_start) ; ((_n) = aga_bfs_explore((_g), (_n))) != NULL; )
+
 #endif /* CCAN_AGA_H */