MCPcopy Create free account
hub / github.com/CodeBendKit/codeseek / _dfs_cycle_detection

Method _dfs_cycle_detection

rust-core/src/services/analyzer.rs:126–160  ·  view source on GitHub ↗
(
        &self,
        function: &'a FunctionInfo,
        code_graph: &'a CodeGraph,
        visited: &mut HashSet<Uuid>,
        rec_stack: &mut HashSet<Uuid>,
        cycle: &mut Vec<&'a Function

Source from the content-addressed store, hash-verified

124 }
125
126 fn _dfs_cycle_detection<'a>(
127 &self,
128 function: &'a FunctionInfo,
129 code_graph: &'a CodeGraph,
130 visited: &mut HashSet<Uuid>,
131 rec_stack: &mut HashSet<Uuid>,
132 cycle: &mut Vec<&'a FunctionInfo>,
133 cycles: &mut Vec<Vec<&'a FunctionInfo>>,
134 ) {
135 visited.insert(function.id);
136 rec_stack.insert(function.id);
137 cycle.push(function);
138
139 let callees = code_graph.get_callees(&function.id);
140 for callee_rel in callees {
141 if let Some(callee) = code_graph.functions.get(&callee_rel.callee_id) {
142 if !visited.contains(&callee.id) {
143 self._dfs_cycle_detection(callee, code_graph, visited, rec_stack, cycle, cycles);
144 } else if rec_stack.contains(&callee.id) {
145 // 找到循环
146 if let Some(start_idx) = cycle.iter().position(|f| f.id == callee.id) {
147 let mut new_cycle = Vec::new();
148 for i in start_idx..cycle.len() {
149 new_cycle.push(cycle[i]);
150 }
151 new_cycle.push(callee);
152 cycles.push(new_cycle);
153 }
154 }
155 }
156 }
157
158 rec_stack.remove(&function.id);
159 cycle.pop();
160 }
161
162 /// 查找最复杂的函数(调用关系最多)
163 pub fn find_most_complex_functions(&self, limit: usize) -> Vec<(&FunctionInfo, usize)> {

Callers 1

Calls 3

insertMethod · 0.80
getMethod · 0.80
get_calleesMethod · 0.45

Tested by

no test coverage detected