sclass LCSortedPairIndex { long[] pairs; int[] index; int ofs; // added to every result *(long[] pairs, int *ofs) { this(pairs); } *(long[] pairs) { this(pairs, null); } // primer is destroyed in the process *(long[] *pairs, LCSortedPairIndex primer) { int[] primerData = primer?.index; if (primer != null) primer.pairs = null; index = lc_sortedPairIndex(pairs, primerData); } int get(long pair) { int i = intArrayBinarySearchWithGeneralizedComparator(index, a -> { int x = cmp(pairs[a], pair); ifdef LCSortedPairIndex_debug printVars_str(+a, val := pairs[a], +pair, +x); endifdef ret x; }); ret i >= 0 ? index[i]+ofs : -1; } }