Closed StephenCleary closed 3 years ago
Alternative:
List<T>
and walk the other collection, removing an equivalent element each time. Downside: O(N^2) instead of O(N). Shouldly and FluentAssertions both take this approach.Alternative:
List<T>
for unmatched elements. Also O(N^2) in the worst case (all elements unique), but only O(N) for collections that happen to be in a compatible order.The commutative combiner could just add hash codes along with a constant value like 65536
to act as a quasi element counter.
The equivalence-class-count approach is fastest (O(N)
), but is complicated by the fact that null
s can be items in the same equivalence class as non-null
items. Wondering if we can use Dictionary<Wrapper<T>>
for some kind of struct Wrapper<T>
type.
Currently
EquateSequence
requires elements to be in corresponding order. This issue is to add some kind of support for a collection equality comparer that ignores ordering of elements. This will require some kind of state, so this will be an expensive comparer to use.The comparer will need to allow a custom element equality comparer, one that may have special
null
handling.High-level algorithm:
ICollection
/ICollection<T>
/IReadOnlyCollection<T>
) aren't equal, thenfalse
. If both counts are0
, thentrue
.Not sure how to handle
GetHashCode
, since there's no order defined for the items nor their equivalence classes. Any hash code combination would have to use a commutative combiner, which is not currently in the library.