Skip to main content

reindex_membership

Function reindex_membership 

Source
pub fn reindex_membership(membership: &mut [i64]) -> Result<Vec<i64>>
Expand description

Relabels a membership vector in place so that community ids are 0..k, and returns the mapping from new to old ids (its length k is the number of communities).

When all ids lie in 0..n (n being the length of membership), new ids are assigned in order of first appearance; otherwise (negative or large ids) they follow the increasing order of the old ids. Time complexity: O(n) in the first case, O(n log n) otherwise.

Binds igraph_reindex_membership.

ยงExamples

use igraph::community::reindex_membership;
// Ids in 0..4: numbered by first appearance.
let mut membership = vec![3, 3, 1, 1];
assert_eq!(reindex_membership(&mut membership).unwrap(), vec![3, 1]);
assert_eq!(membership, vec![0, 0, 1, 1]);
// An id outside 0..4: numbered in increasing order of the old ids.
let mut membership = vec![7, 3, 7, 10];
let new_to_old = reindex_membership(&mut membership).unwrap();
assert_eq!(membership, vec![1, 0, 1, 2]);
assert_eq!(new_to_old, vec![3, 7, 10]);