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

Function local_selectivity_at

nodedb-vector/src/navix/selectivity.rs:16–25  ·  view source on GitHub ↗

Compute the local selectivity at a graph node. Returns the fraction of 1-hop neighbors that are present in `allowed`. Range: `[0.0, 1.0]`. An empty neighborhood returns `0.0`.

(node_neighbors: &[u32], allowed: &RoaringBitmap)

Source from the content-addressed store, hash-verified

14/// Returns the fraction of 1-hop neighbors that are present in `allowed`.
15/// Range: `[0.0, 1.0]`. An empty neighborhood returns `0.0`.
16pub fn local_selectivity_at(node_neighbors: &[u32], allowed: &RoaringBitmap) -> f32 {
17 if node_neighbors.is_empty() {
18 return 0.0;
19 }
20 let matched = node_neighbors
21 .iter()
22 .filter(|&&n| allowed.contains(n))
23 .count();
24 matched as f32 / node_neighbors.len() as f32
25}
26
27/// Heuristic chosen for expanding a given hop based on local selectivity.
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]

Callers 1

navix_search_layer_0Function · 0.85

Calls 5

is_emptyMethod · 0.45
countMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected