Commit f9274cce authored by David Gibson's avatar David Gibson

aga,agar: Add edge costs

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: default avatarDavid Gibson <david@gibson.dropbear.id.au>
parent 8835db12
...@@ -93,6 +93,7 @@ int aga_edge_info(const struct aga_graph *g, const struct aga_node *n, ...@@ -93,6 +93,7 @@ int aga_edge_info(const struct aga_graph *g, const struct aga_node *n,
int rc; int rc;
ei->to = NULL; ei->to = NULL;
ei->icost = 1;
rc = g->edge_info(g, n, e, ei); rc = g->edge_info(g, n, e, ei);
assert(rc <= 0); assert(rc <= 0);
return rc; return rc;
......
...@@ -72,6 +72,10 @@ ...@@ -72,6 +72,10 @@
* reference to that node by the edge callback for *any* node and * reference to that node by the edge callback for *any* node and
* index MUST use the same pointer. * 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 * Concurrency
* =========== * ===========
* *
...@@ -127,9 +131,13 @@ typedef const void *(*aga_next_edge_fn)(const struct aga_graph *g, ...@@ -127,9 +131,13 @@ typedef const void *(*aga_next_edge_fn)(const struct aga_graph *g,
const struct aga_node *n, const struct aga_node *n,
const void *e); const void *e);
typedef long aga_icost_t;
struct aga_edge_info { struct aga_edge_info {
struct aga_node *to; struct aga_node *to;
aga_icost_t icost; /* integer edge cost */
}; };
typedef int (*aga_edge_info_fn)(const struct aga_graph *g, typedef int (*aga_edge_info_fn)(const struct aga_graph *g,
const struct aga_node *n, const struct aga_node *n,
const void *e, struct aga_edge_info *ei); const void *e, struct aga_edge_info *ei);
......
...@@ -79,6 +79,7 @@ static int convert_edge_info(const struct aga_graph *g, ...@@ -79,6 +79,7 @@ static int convert_edge_info(const struct aga_graph *g,
int rc; int rc;
eir.to = NULL; eir.to = NULL;
eir.icost = ei->icost; /* Inherit the default from aga */
rc = sr->gr->edge_info(sr->gr, nr, e, &eir); rc = sr->gr->edge_info(sr->gr, nr, e, &eir);
...@@ -87,6 +88,8 @@ static int convert_edge_info(const struct aga_graph *g, ...@@ -87,6 +88,8 @@ static int convert_edge_info(const struct aga_graph *g,
else else
ei->to = NULL; ei->to = NULL;
ei->icost = eir.icost;
return rc; return rc;
} }
...@@ -164,6 +167,7 @@ int agar_edge_info(const struct agar_graph *gr, const void *nr, const void *e, ...@@ -164,6 +167,7 @@ int agar_edge_info(const struct agar_graph *gr, const void *nr, const void *e,
int rc; int rc;
eir->to = NULL; eir->to = NULL;
eir->icost = 1;
rc = gr->edge_info(gr, nr, e, eir); rc = gr->edge_info(gr, nr, e, eir);
assert(rc <= 0); assert(rc <= 0);
return rc; return rc;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
struct agar_edge_info { struct agar_edge_info {
const void *to; const void *to;
aga_icost_t icost; /* integer edge cost */
}; };
struct agar_graph; struct agar_graph;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment