Exemple #1
0
        public bool RemoveEdges(IEnumerable <DirectedEdge <V, E> > edgesToRemove)
        {
            HashSet <DirectedEdge <V, E> > edgesToRemoveSet = edgesToRemove.ToHashSet(myEdgeComparer);
            IEnumerable <Tuple <V, V> >    fromTos          = edgesToRemove.Select(x => Tuple.Create(x.From, x.To));
            bool result = myEdges.Remove(fromTos, (fromId, toId, edge) => edgesToRemoveSet.Contains(edge));

            return(result);
        }
        public void Remove()
        {
            DoubleKeyMultiDictionary <string, string, int> dictionary = new DoubleKeyMultiDictionary <string, string, int>();

            dictionary.Add("k1", "k2", 10);
            dictionary.Add("k1", "k2", 10); // the same keys and the value

            dictionary.Add("k3", "k4", 20);

            Assert.IsTrue(dictionary.Remove("k1", "k2"));
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(20, dictionary.GetValues("k3", "k4").First());



            dictionary = new DoubleKeyMultiDictionary <string, string, int>();

            dictionary.Add("k1", "k2", 10);
            dictionary.Add("k1", "k2", 10); // the same keys and the value

            dictionary.Add("k3", "k4", 20);

            int  counter = 0;
            bool result  = dictionary.Remove("k1", "k2", (k1, k2, v) =>
            {
                ++counter;
                return(counter < 2);
            }
                                             );

            Assert.IsTrue(result);
            Assert.AreEqual(2, dictionary.Count);
            Assert.AreEqual(10, dictionary.GetValues("k1", "k2").First());
            Assert.AreEqual(20, dictionary.GetValues("k3", "k4").First());


            Assert.IsFalse(dictionary.Remove("bla1", "bla2"));
        }
        public void Remove_Sequence()
        {
            DoubleKeyMultiDictionary <string, string, int> dictionary = new DoubleKeyMultiDictionary <string, string, int>();

            dictionary.Add("k1", "k2", 10);
            dictionary.Add("k1", "k2", 10); // the same keys and the value

            dictionary.Add("k3", "k4", 20);
            dictionary.Add("k3", "k5", 30);

            Tuple <string, string>[] toRemove = new Tuple <string, string>[] { Tuple.Create("k1", "k2"), Tuple.Create("k3", "k4"), };

            Assert.IsTrue(dictionary.Remove(toRemove));
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(30, dictionary.GetValues("k3", "k5").First());
        }