public override bool Contains(TValue value) { foreach (TValue v in this) { if (myDictionary.EqualValues(v, value)) { return(true); } } return(false); }
public override bool Contains(ICollection <TValue> values) { if (values == null) { return(false); } TValue[] valueArray = Algorithms.ToArray(values); foreach (ICollection <TValue> v in this) { if (v.Count != valueArray.Length) { continue; } // First check in order for efficiency. if (Algorithms.EqualCollections(v, values, myDictionary.EqualValues)) { return(true); } // Now check not in order. We can't use Algorithms.EqualSets, because we don't // have an IEqualityComparer, just the ability to compare for equality. Unfortunately this is N squared, // but there isn't a good choice here. We don't really expect this method to be used much. bool[] found = new bool[valueArray.Length]; foreach (TValue x in v) { for (int i = 0; i < valueArray.Length; ++i) { if (!found[i] && myDictionary.EqualValues(x, valueArray[i])) { found[i] = true; } } } if (Array.IndexOf(found, false) < 0) { return(true); // every item was found. The sets must be equal. } } return(false); }