public override bool Contains(ICollection <TValue> values) { if (values == null) { return(false); } TValue[] valueArray = Algorithms.ToArray(values); foreach (var 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. var found = new bool[valueArray.Length]; foreach (TValue x in v) { for (var 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); }
public override bool Contains(TValue value) { return(this.Any(v => _myDictionary.EqualValues(v, value))); }