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)
| 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`. |
| 16 | pub 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)] |