static int indexOfIntPairInContentsIndexedList(IContentsIndexedList2 l, Int pa, Int pb, int idx) { SortedSet setA = l.indicesOf_treeSetOfHasIndex(pa); if (setA == null) ret -1; SortedSet setB = l.indicesOf_treeSetOfHasIndex(pb); if (setB == null) ret -1; // Take size now because size of a tailSet is costly to compute if (setA.size() <= setB.size()) { // quickly skip entries left of idx if (idx > 0) setA = setA.tailSet(HasIndex(idx)); // scan set, check if it's a pair int n = l.size(); for (HasIndex hi : setA) { int i = hi.idx; if (i+1 < n && eq(l.get(i+1), pb)) ret i; } } else { // quickly skip entries left of idx+1 setB = setB.tailSet(HasIndex(idx+1)); // scan set, check if it's a pair for (HasIndex hi : setB) { int i = hi.idx; if (eq(l.get(i-1), pa)) ret i-1; } } ret -1; }