remove method

bool remove(
  1. E e
)

Remove a single element that is equal to e.

If there are multiple elements identical to e, only the first will be removed. To remove all, use something like:

set.removeWhere((a) => a == e);

Implementation

bool remove(E e) {
  var bucket = _backingSet.lookup({e});
  if (bucket == null || !bucket.contains(e)) {
    // We need a fallback in case [e] has changed and it's no longer found by
    // lookup. Note: changing priorities will leave the splay set on an
    // unknown state; other methods might not work. You must call rebalance to
    // make sure the state is consistent. This is just for convenient usage by
    // the rebalancing method itself.
    final possibleBuckets = _backingSet
        .where((bucket) => bucket.any((element) => identical(element, e)));
    if (possibleBuckets.isNotEmpty) {
      bucket = possibleBuckets.first;
    }
  }
  if (bucket == null) {
    return false;
  }
  final result = bucket.remove(e);
  if (result) {
    _length--;
    // If the removal resulted in an empty bucket, remove the bucket as well.
    _backingSet.remove(<E>{});
    _validReverseCache = false;
  }
  return result;
}