use crate::id::{GraphNodeId, position};
use super::index::{AnalysisContext, SelectedIndexes};
#[derive(Clone, Copy, Debug)]
pub struct DegreeCentrality {
node: GraphNodeId,
incoming: u32,
outgoing: u32,
}
impl DegreeCentrality {
pub fn node(self) -> GraphNodeId {
self.node
}
pub fn incoming(self) -> u32 {
self.incoming
}
pub fn outgoing(self) -> u32 {
self.outgoing
}
}
pub(crate) fn degree(analysis: &AnalysisContext<'_>) -> Box<[DegreeCentrality]> {
let indexes = analysis.indexes();
(0..indexes.node_count())
.map(|at| counted(indexes, GraphNodeId::new(position(at))))
.collect()
}
fn counted(indexes: &SelectedIndexes, node: GraphNodeId) -> DegreeCentrality {
DegreeCentrality {
node,
incoming: position(indexes.incoming(node).len()),
outgoing: position(indexes.outgoing(node).len()),
}
}