why linq’s except extension method does not have Except<TSource> Method (IEnumerable<TSource>,HashSet<TSource>) overload?
for example
var query = A.Except(B).where(x=>Criteria(x))
foreach(item in query)
{
B.add(item);
DoSomething(item);
}
Given B is HashSet<T>, A is IEnumerable<T> or ICollection<T>
Here in each iteration Except take O(|B|) time.
why there is not a method that just take O(1) time, as B is Hashset anyway.
Update
my crude way is
var query = A.where(x=>!B.contains(x)).where(x=>Criteria(x))
No it doesn’t.
Exceptis implemented internally with a collection similar toHashSet<T>. You can have a look at Jon Skeet’s proposed implementation in Edulinq. All elements inBare placed in aHashSet<T>, then elements of A are enumerated; if they’re not in theHashSet(checking this is a O(1) operation), they are returned in the output sequence.