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

Function compute_histogram

nodedb-graph/src/csr/statistics.rs:197–223  ·  view source on GitHub ↗

Compute degree distribution histogram from a degree array.

(degrees: &[usize])

Source from the content-addressed store, hash-verified

195
196/// Compute degree distribution histogram from a degree array.
197fn compute_histogram(degrees: &[usize]) -> DegreeHistogram {
198 if degrees.is_empty() {
199 return DegreeHistogram {
200 min: 0,
201 max: 0,
202 avg: 0.0,
203 p50: 0,
204 p95: 0,
205 p99: 0,
206 };
207 }
208
209 let mut sorted = degrees.to_vec();
210 sorted.sort_unstable();
211
212 let n = sorted.len();
213 let sum: usize = sorted.iter().sum();
214
215 DegreeHistogram {
216 min: sorted[0],
217 max: sorted[n - 1],
218 avg: sum as f64 / n as f64,
219 p50: sorted[n / 2],
220 p95: sorted[(n as f64 * 0.95) as usize],
221 p99: sorted[((n as f64 * 0.99) as usize).min(n - 1)],
222 }
223}
224
225#[cfg(test)]
226mod tests {

Callers 1

compute_statisticsMethod · 0.85

Calls 5

sumMethod · 0.80
is_emptyMethod · 0.45
to_vecMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected