public static ImmutableMap <string, ICollection <NodeId> > TransposeNodeToLabels(IDictionary <NodeId, ICollection <string> > mapNodeToLabels) { IDictionary <string, ICollection <NodeId> > mapLabelsToNodes = new Dictionary <string , ICollection <NodeId> >(); foreach (KeyValuePair <NodeId, ICollection <string> > entry in mapNodeToLabels) { NodeId node = entry.Key; ICollection <string> setLabels = entry.Value; foreach (string label in setLabels) { ICollection <NodeId> setNode = mapLabelsToNodes[label]; if (setNode == null) { setNode = new HashSet <NodeId>(); } setNode.AddItem(NodeId.NewInstance(node.GetHost(), node.GetPort())); mapLabelsToNodes[label] = setNode; } } return(ImmutableMap.CopyOf(mapLabelsToNodes)); }