[ccan] [PATCH 7/7] aga: Add edge costs
David Gibson
david at gibson.dropbear.id.au
Fri Jul 10 01:58:37 AEST 2015
This adds support for the edge_info function giving a cost or length for an
edge. This can be given as a (long) integer or a (double) float. Or both,
but that might have odd effects.
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
ccan/aga/aga.c | 4 ++++
ccan/aga/aga.h | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/ccan/aga/aga.c b/ccan/aga/aga.c
index ee3f810..1737923 100644
--- a/ccan/aga/aga.c
+++ b/ccan/aga/aga.c
@@ -87,7 +87,11 @@ int aga_edge_info(const struct aga_graph *g, const struct aga_node *n,
int rc;
ei->to = NULL;
+ ei->icost = 1;
+ ei->fcost = 1.0;
rc = g->edge_info(g, n, e, ei);
assert(rc <= 0);
+ if ((ei->fcost == 1.0) && (ei->icost != 1))
+ ei->fcost = (aga_fcost_t)ei->icost;
return rc;
}
diff --git a/ccan/aga/aga.h b/ccan/aga/aga.h
index 4ec6bc6..ea79b73 100644
--- a/ccan/aga/aga.h
+++ b/ccan/aga/aga.h
@@ -72,6 +72,16 @@
* 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.
+ *
+ * - The ei->fcost field MAY be set by the edge_info callback to
+ * indicate the edge's cost / length represented as a floating point
+ * number (of type aga_fcost_t). If edge_info sets icost but not
+ * fcost, fcost will be set to icost converted to floating point.
+ * Otherwise, it defaults to 1.0.
+ *
* Concurrency
* ===========
*
@@ -129,8 +139,13 @@ struct aga_node {
} u;
};
+typedef long aga_icost_t;
+typedef double aga_fcost_t;
+
struct aga_edge_info {
struct aga_node *to;
+ aga_icost_t icost; /* integer edge cost */
+ aga_fcost_t fcost; /* floating point edge cost */
};
typedef const void *(*aga_first_edge_fn)(const struct aga_graph *g,
--
2.4.3
More information about the ccan
mailing list