@@ -635,6 +635,11 @@ private void appendRelationFrontierMethods(StringBuilder source, int patternOrdi
635635 source .append (" return seekSlot" ).append (suffix ).append ("(0L);\n " );
636636 source .append (" }\n \n " );
637637 source .append (" private boolean seekSlot" ).append (suffix ).append ("(long target) {\n " );
638+ source .append (" long[] previousFrontierValues" )
639+ .append (suffix )
640+ .append (" = frontierValues" )
641+ .append (suffix )
642+ .append (";\n " );
638643 if (component == patternShape .derivedSourceComponent ()) {
639644 source .append (" frontierValues" )
640645 .append (suffix )
@@ -653,7 +658,15 @@ private void appendRelationFrontierMethods(StringBuilder source, int patternOrdi
653658 .append (suffix )
654659 .append (" = seekFrontier(frontierValues" )
655660 .append (suffix )
656- .append (", target);\n " );
661+ .append (", target, frontierAvailable" )
662+ .append (suffix )
663+ .append (" && frontierValues" )
664+ .append (suffix )
665+ .append (" == previousFrontierValues" )
666+ .append (suffix )
667+ .append (" ? frontierIndex" )
668+ .append (suffix )
669+ .append (" : -1);\n " );
657670 source .append (" if (frontierIndex" )
658671 .append (suffix )
659672 .append (" >= frontierValues" )
@@ -1163,8 +1176,32 @@ private void appendCloseCursorResources(StringBuilder source, int patternOrdinal
11631176 private void appendHelpers (StringBuilder source ) {
11641177 source .append (" private static final long[] EMPTY_FRONTIER_VALUES = new long[0];\n \n " );
11651178 if (relationGroups .length > 0 ) {
1166- source .append (" private static int seekFrontier(long[] values, long target) {\n " );
1167- source .append (" int index = java.util.Arrays.binarySearch(values, target);\n " );
1179+ source .append (" private static int seekFrontier(long[] values, long target, int hintIndex) {\n " );
1180+ source .append (" if (hintIndex < 0 || hintIndex >= values.length) {\n " );
1181+ source .append (" int index = java.util.Arrays.binarySearch(values, target);\n " );
1182+ source .append (" return index >= 0 ? index : -index - 1;\n " );
1183+ source .append (" }\n " );
1184+ source .append (" long hintValue = values[hintIndex];\n " );
1185+ source .append (" if (hintValue == target) {\n " );
1186+ source .append (" return hintIndex;\n " );
1187+ source .append (" }\n " );
1188+ source .append (" if (hintValue < target) {\n " );
1189+ source .append (" int nextIndex = hintIndex + 1;\n " );
1190+ source .append (" if (nextIndex >= values.length) {\n " );
1191+ source .append (" return values.length;\n " );
1192+ source .append (" }\n " );
1193+ source .append (" if (values[nextIndex] >= target) {\n " );
1194+ source .append (" return nextIndex;\n " );
1195+ source .append (" }\n " );
1196+ source .append (
1197+ " int index = java.util.Arrays.binarySearch(values, nextIndex + 1, values.length, target);\n " );
1198+ source .append (" return index >= 0 ? index : -index - 1;\n " );
1199+ source .append (" }\n " );
1200+ source .append (" int previousIndex = hintIndex - 1;\n " );
1201+ source .append (" if (previousIndex >= 0 && values[previousIndex] < target) {\n " );
1202+ source .append (" return hintIndex;\n " );
1203+ source .append (" }\n " );
1204+ source .append (" int index = java.util.Arrays.binarySearch(values, 0, hintIndex, target);\n " );
11681205 source .append (" return index >= 0 ? index : -index - 1;\n " );
11691206 source .append (" }\n \n " );
11701207 source .append (" private static int mixFrontierCacheKey(long value) {\n " );
0 commit comments