pub struct CommunityAssignment {
pub map: BTreeMap<NodeId, CommunityId>,
pub members: BTreeMap<CommunityId, Vec<NodeId>>,
pub modularity: f32,
pub seed: u64,
}Expand description
Result of a community-detection run over an AdjacencyIndex.
Fields§
§map: BTreeMap<NodeId, CommunityId>Canonical NodeId -> CommunityId map. Keyed by BTreeMap so
iteration is deterministic (ascending NodeId).
members: BTreeMap<CommunityId, Vec<NodeId>>Inverse map CommunityId -> [NodeId]. Each member vector is
sorted ascending (derived from BTreeMap iteration order over
map). Precomputed at construction so members_of is O(1)
lookup + O(|C|) slice return; the CommunityExpander stage
(C3 FIX-1) needs this on the retrieval hot path.
modularity: f32Modularity score of this partition (higher is better; range
[-0.5, 1.0] for undirected graphs).
seed: u64Seed that produced this partition. Threaded into content_cid
so distinct seeds produce distinct CIDs even when the
partition map happens to collide.
Implementations§
Source§impl CommunityAssignment
impl CommunityAssignment
Sourcepub fn community_of(&self, node: NodeId) -> Option<CommunityId>
pub fn community_of(&self, node: NodeId) -> Option<CommunityId>
Look up the community of node. Returns None for nodes not
present in any edge of the underlying graph.
Sourcepub fn members_of(&self, community: CommunityId) -> &[NodeId] ⓘ
pub fn members_of(&self, community: CommunityId) -> &[NodeId] ⓘ
All nodes assigned to community. Sorted ascending by
NodeId for determinism. Empty slice if the id is unknown.
Sourcepub fn community_count(&self) -> usize
pub fn community_count(&self) -> usize
Number of distinct communities.
Sourcepub fn content_cid(&self) -> Cid
pub fn content_cid(&self) -> Cid
Content-addressable identity of this assignment.
CID preimage:
b"mnem/community/v1" || seed_be_u64 || concat(node_id_bytes || cid_be_u32)
where the (node, community) pairs iterate in ascending
NodeId order (guaranteed by BTreeMap). Wrapped in
CIDv1(codec=raw, multihash=sha2-256). Domain-separated from
other mnem object classes by the leading tag.
Trait Implementations§
Source§impl Clone for CommunityAssignment
impl Clone for CommunityAssignment
Source§fn clone(&self) -> CommunityAssignment
fn clone(&self) -> CommunityAssignment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more