internal static void CreatePartition(KeyManager manager, int firstId, int secondId) { Partition partition = new Partition(firstId); partition.AddNode(manager, firstId); partition.AddNode(manager, secondId); }
/// <summary> /// Ensures firstId and secondId belong to the same partition /// </summary> internal void AssociateNodes(int firstId, int secondId) { if (firstId == secondId) { // A node is (trivially) associated with itself return; } Partition firstPartition = _identifiers[firstId].Partition; if (null != firstPartition) { Partition secondPartition = _identifiers[secondId].Partition; if (null != secondPartition) { // merge partitions firstPartition.Merge(this, secondPartition); } else { // add y to existing x partition firstPartition.AddNode(this, secondId); } } else { Partition secondPartition = _identifiers[secondId].Partition; if (null != secondPartition) { // add x to existing y partition secondPartition.AddNode(this, firstId); } else { // Neither node is known Partition.CreatePartition(this, firstId, secondId); } } }