]> git.ozlabs.org Git - ccan/commitdiff
aga,agar: Add edge costs
authorDavid Gibson <david@gibson.dropbear.id.au>
Fri, 6 Nov 2015 01:23:53 +0000 (12:23 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Fri, 20 Nov 2015 06:08:34 +0000 (17:08 +1100)
This allows the edge_info callback to supply a cost or length for an edge.
For now we only support 'long' valued costs.  If the callback doesn't
supply a cost, it's considered cost 1.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/aga/aga.c
ccan/aga/aga.h
ccan/agar/agar.c
ccan/agar/agar.h

index c721b1440e6de41b8e69fa8ad2ae67d8ca408fa9..a6e0539dc8ee53502f3d36c3428fd29d838b7a1a 100644 (file)
@@ -93,6 +93,7 @@ int aga_edge_info(const struct aga_graph *g, const struct aga_node *n,
        int rc;
 
        ei->to = NULL;
+       ei->icost = 1;
        rc = g->edge_info(g, n, e, ei);
        assert(rc <= 0);
        return rc;
index 867515030a560501ed0c158ec63c406a39a335c7..a8a888be1a9d584045e99659bb465459e01af895 100644 (file)
  *   reference to that node by the edge callback for *any* node and
  *   index MUST use the same pointer.
  *
+ * - The ei->icost field MAY be set by the edge_info callback to
+ *   indicate the edge's cost / length represented as an integer (of
+ *   type aga_icost_t),  Otherwise the cost defaults to 1.
+ *
  * Concurrency
  * ===========
  *
@@ -127,9 +131,13 @@ typedef const void *(*aga_next_edge_fn)(const struct aga_graph *g,
                                        const struct aga_node *n,
                                        const void *e);
 
+typedef long aga_icost_t;
+
 struct aga_edge_info {
        struct aga_node *to;
+       aga_icost_t icost; /* integer edge cost */
 };
+
 typedef int (*aga_edge_info_fn)(const struct aga_graph *g,
                                const struct aga_node *n,
                                const void *e, struct aga_edge_info *ei);
index b2809abd3bb91fc0a206ed698b3f0fef564dc7e7..2be9dafedfade6a8fbec23d640c76dd77d6fed46 100644 (file)
@@ -79,6 +79,7 @@ static int convert_edge_info(const struct aga_graph *g,
        int rc;
 
        eir.to = NULL;
+       eir.icost = ei->icost; /* Inherit the default from aga */
 
        rc = sr->gr->edge_info(sr->gr, nr, e, &eir);
 
@@ -87,6 +88,8 @@ static int convert_edge_info(const struct aga_graph *g,
        else
                ei->to = NULL;
 
+       ei->icost = eir.icost;
+
        return rc;
 }
 
@@ -164,6 +167,7 @@ int agar_edge_info(const struct agar_graph *gr, const void *nr, const void *e,
        int rc;
 
        eir->to = NULL;
+       eir->icost = 1;
        rc = gr->edge_info(gr, nr, e, eir);
        assert(rc <= 0);
        return rc;
index 495ef7c3bdf548b354234e365c9d7b50bd0b5ead..d63615add7e9d4e53e90f52a441b9b8bb54ed5a6 100644 (file)
@@ -9,6 +9,7 @@
 
 struct agar_edge_info {
        const void *to;
+       aga_icost_t icost; /* integer edge cost */
 };
 
 struct agar_graph;