ComparingOrderedSet<E> constructor
ComparingOrderedSet<E> ([
- int compare(
- E e1,
- E e2
Creates a new OrderedSet with the given compare function.
If the compare
function is omitted, it defaults to Comparable.compare,
and the elements must be comparable.
Implementation
ComparingOrderedSet([int Function(E e1, E e2)? compare]) {
final comparator = compare ?? _defaultCompare<E>();
_backingSet = SplayTreeSet<LinkedHashSet<E>>((Set<E> l1, Set<E> l2) {
if (l1.isEmpty) {
if (l2.isEmpty) {
return 0;
}
return -1;
}
if (l2.isEmpty) {
return 1;
}
return comparator(l1.first, l2.first);
});
_length = 0;
}