Skip to content

9.4 Carry edge data over to a transformed graph

You get the edge mapping between a transformed graph and the original, and gather edge data through it.

You derived a new graph from an old one and want your data on the edges, such as weights, counts or labels, to come along. This data is kept in arrays by edge index. The new graph numbers its edges anew, just like its nodes. A mapping of the node IDs tells which new node is which old one, but not which new edge is which old one. You need a mapping of the edges. This comes up:

  • after you take a subgraph, when an analysis of it needs the weights or labels of its edges;
  • after a renumbering, which changes the edge indices along with the node IDs;
  • after edges were added or left out by building the graph again, which shifts the edge indices;
  • when you translate results on the new graph, such as the edges a search followed, back to the original edges.

The example graph calls models the calls between the ten methods of a small program. It has an edge from each method to each method it calls. A place in the code where one method calls another is called a call site. The array siteCountsite_countsiteCountsiteCount holds the number of call sites of each call: run calls show from two places, and parse calls itself from two. The graph loading is the subgraph of the methods that load reaches. It numbers nodes and edges anew. The mapping newToOldnew_to_oldnewToOldnewToOld gives the old node ID of each of its nodes. See Take the subgraph of some nodes for how to build both. How many call sites does each call of the subgraph have? The picture after shows the subgraph with the call sites on its edges:

The calls with their call sites
The subgraph of the methods load reaches, with its call sites
1111211111210: main1: parseArgs2: run3: load4: save5: show6: parse7: format8: read9: write
1120: load1: parse2: read
Context
  • Start node
Output
  • Call with its call sites
EdgeMapping edges = Graphs.edgeMapping(loading, calls, newToOld);
int[] loadingSiteCount = edges.gather(siteCount);
// loadingSiteCount: [1, 1, 2] - load -> parse, load -> read, parse -> parse
Full example
let edges = graphs::edge_mapping(&loading, &calls, &new_to_old);
let loading_site_count = edges.gather(&site_count);
// loading_site_count: [1, 1, 2] - load -> parse, load -> read, parse -> parse
Full example
const edges = Graphs.edgeMapping(loading, calls, newToOld);
const loadingSiteCount = edges.gather(siteCount);
// loadingSiteCount: [1, 1, 2] - load -> parse, load -> read, parse -> parse
Full example
EdgeMapping edges = Graphs.EdgeMapping(loading, calls, newToOld);
int[] loadingSiteCount = edges.Gather(siteCount);
// loadingSiteCount: [1, 1, 2] - load -> parse, load -> read, parse -> parse
Full example

The edge mapping leads from each edge of loading to the edge of calls it comes from. gathergathergatherGather carries the call sites over through it. The result holds 1, 1 and 2 for load -> parse, load -> read and parse -> parse, in the order of their new edge indices, as in the picture after.