intersection method

List<(int, D)> intersection(
  1. List<D> ids
)

Returns the intersection between this collection and ids.

Each entry is a pair of (index, id) where index refers to this collection's internal ordering.

Implementation

List<(int, D)> intersection(List<D> ids) {
  var l = <(int, D)>[];

  final compare = this.compare;

  if (compare != null) {
    for (var id in ids) {
      var idx = binarySearchIndex(id);
      if (idx >= 0) {
        l.add((idx, id));
      }
    }
  } else {
    final length = _ids.length;
    for (var i = 0; i < length; ++i) {
      var id1 = _ids[i];
      for (var id2 in ids) {
        if (id1 == id2) {
          l.add((i, id2));
        }
      }
    }
  }

  return l;
}