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

Method enable_weights

nodedb-graph/src/csr/weights.rs:14–40  ·  view source on GitHub ↗

Enable weight tracking. Backfills existing buffer entries with 1.0.

(&mut self)

Source from the content-addressed store, hash-verified

12impl CsrIndex {
13 /// Enable weight tracking. Backfills existing buffer entries with 1.0.
14 pub(crate) fn enable_weights(&mut self) {
15 self.has_weights = true;
16
17 // Backfill existing dense arrays with 1.0.
18 if !self.out_targets.is_empty() {
19 self.out_weights = Some(vec![1.0; self.out_targets.len()].into());
20 }
21 if !self.in_targets.is_empty() {
22 self.in_weights = Some(vec![1.0; self.in_targets.len()].into());
23 }
24
25 // Backfill existing buffer entries with 1.0.
26 for (buf, wbuf) in self
27 .buffer_out
28 .iter()
29 .zip(self.buffer_out_weights.iter_mut())
30 {
31 if wbuf.len() < buf.len() {
32 wbuf.resize(buf.len(), 1.0);
33 }
34 }
35 for (buf, wbuf) in self.buffer_in.iter().zip(self.buffer_in_weights.iter_mut()) {
36 if wbuf.len() < buf.len() {
37 wbuf.resize(buf.len(), 1.0);
38 }
39 }
40 }
41
42 /// Whether this CSR has any weighted edges.
43 pub fn has_weights(&self) -> bool {

Callers 1

add_edge_internalMethod · 0.80

Calls 4

iter_mutMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected