OrderedSet<E> constructor

OrderedSet<E>([
  1. int compare(
    1. E e1,
    2. 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

OrderedSet([int Function(E e1, E e2)? compare]) {
  final comparator = compare ?? _defaultCompare<E>();
  _backingSet = SplayTreeSet<List<E>>((List<E> l1, List<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;
}