Skip to main content

remapped

Function remapped 

Source
pub fn remapped(graph: &Graph, new_to_old: &NodeMapping) -> Graph
Expand description

Returns graph with its nodes renumbered by new_to_old: node i of the result is node new_to_old.get(i) of graph.

The result has the edges of graph between the nodes that new_to_old maps to; the other nodes are left out, with their edges. The factories of NodeMapping make the mapping: for_subgraph and its variants select nodes, for_permutation and reindex reorder all of them. Data on the nodes follows with the gather functions of the mapping, data on the edges with edge_mapping. Here, calls holds the calls between the methods of a program, and the methods that load reaches become a graph of their own, with their names from names:

let new_to_old =
    NodeMapping::for_subgraph_sorted(&graphs::reachable_from(&calls, load))?;
let loading = graphs::remapped(&calls, &new_to_old);
let loading_names = new_to_old.gather(names);
// loading_names: ["load", "parse", "read"]
// loading: load -> parse, load -> read, parse -> parse

To merge nodes into groups instead, use NodePartition::condense.

Time: O(node_count + edge_count log max_out_degree). Memory: 4 bytes per node and per edge for the result; while it runs, 4 x node_count bytes more.

ยงPanics

With an invalid argument message if a node of the result is not mapped, or two map to the same node; with an index out of bounds message if a node of the result maps to an ID that is not a node of graph.