private static int Main(string[] args) { var multi = new SortedMultiMap <string, int>(); var multi2 = new SortedMultiMap <string, int>(); try { multi.Add("a", 1); multi.Add("x", 2); multi.Add("x", 4); multi.Add("x", 6); multi.Add("x", 7); multi2.Add("x", 2); multi2.Add("x", 3); multi2.Add("a", 8); //multi.Intersect(multi2); multi.Union(multi2); foreach (KeyValuePair <string, int> item in multi) { Console.WriteLine("{0}-{1}", item.Key, item.Value); } } catch (ArgumentException e) { Console.WriteLine(e.Message); } return(0); }
internal static void Union <K, V>(this SortedMultiMap <K, V> originalMap, SortedMultiMap <K, V> secondMap) { foreach (KeyValuePair <K, V> item in secondMap) { originalMap.Add(item.Key, item.Value); } }
internal static void Intersect <K, V>(this SortedMultiMap <K, V> originalMap, SortedMultiMap <K, V> secondMap) { var newMap = new SortedMultiMap <K, V>(); foreach (KeyValuePair <K, V> item in originalMap) { if (secondMap.HasKey(item.Key)) { var isCommonValue = secondMap.Get(item.Key).Contains(item.Value); if (isCommonValue) { newMap.Add(item.Key, item.Value); } } } originalMap.Clear(); foreach (KeyValuePair <K, V> item in newMap) { originalMap.Add(item.Key, item.Value); } }