MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / compute_density

Method compute_density

src/analysis/adg.rs:264–295  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

262 }
263
264 pub fn compute_density(&self) -> usize {
265 let mut undigraph: Graph<Node, (), Undirected> = Graph::default();
266 for node in self.graph.node_indices() {
267 undigraph.add_node(self.graph[node].clone());
268 }
269
270 for edge in self.graph.edge_references() {
271 let (a, b) = (edge.source(), edge.target());
272 if !undigraph.contains_edge(a, b) && !undigraph.contains_edge(b, a) {
273 undigraph.add_edge(a, b, ());
274 }
275 }
276 let scc = petgraph::algo::kosaraju_scc(&undigraph);
277 // compute the number of nodes in the largest connected component.
278 let density = scc
279 .iter()
280 .map(|subgraph| {
281 let mut api_calls = Vec::new();
282 // count number of api calls in each subgraph
283 for node in subgraph {
284 let node_weight = undigraph.node_weight(*node).unwrap();
285 let node_name = node_weight.get_name();
286 if get_func_gadget(&node_name).is_some() {
287 api_calls.push(node);
288 }
289 }
290 api_calls.len()
291 })
292 .max()
293 .unwrap_or(1);
294 density
295 }
296}
297
298/// Taint structure attached with each symbol.

Callers 1

compute_qualityMethod · 0.80

Calls 5

get_func_gadgetFunction · 0.85
add_nodeMethod · 0.80
add_edgeMethod · 0.45
get_nameMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected