MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / apply_merges

Method apply_merges

nodedb-cluster/src/distributed_graph/wcc.rs:140–173  ·  view source on GitHub ↗

Apply incoming merges. Returns number of labels changed.

(&mut self, merges: &[(String, String)])

Source from the content-addressed store, hash-verified

138
139 /// Apply incoming merges. Returns number of labels changed.
140 pub fn apply_merges(&mut self, merges: &[(String, String)]) -> usize {
141 let mut changed = 0;
142
143 let name_to_id: HashMap<&str, usize> = self
144 .node_names
145 .iter()
146 .enumerate()
147 .map(|(i, n)| (n.as_str(), i))
148 .collect();
149
150 for (vertex_name, remote_label) in merges {
151 let Some(&local_id) = name_to_id.get(vertex_name.as_str()) else {
152 continue;
153 };
154
155 let root = find_static(&self.parent, local_id);
156 let local_label = &self.global_labels[root];
157
158 if local_label != remote_label && *remote_label < *local_label {
159 self.global_labels[root] = remote_label.clone();
160 changed += 1;
161 }
162 }
163
164 // Propagate updated labels to all nodes.
165 for i in 0..self.vertex_count {
166 let root = find_static(&self.parent, i);
167 if i != root {
168 self.global_labels[i] = self.global_labels[root].clone();
169 }
170 }
171
172 changed
173 }
174
175 /// Get current component assignment: (vertex_name, global_label).
176 pub fn component_labels(&self) -> Vec<(String, String)> {

Calls 6

find_staticFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
as_strMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45