@@ -272,39 +272,50 @@ public boolean isLastTriplePositionBoundToOrder() {
272
272
273
273
private boolean gotoOrder (long id , TripleComponentRole role ) {
274
274
switch (role ) {
275
- case SUBJECT -> {
276
- if (patX != 0 ) {
277
- return id == patX ; // can't jump or already on the right element
278
- }
279
-
280
- patX = id ;
281
- findRange ();
282
- patX = 0 ;
275
+ case SUBJECT -> {
276
+ if (patX != 0 ) {
277
+ return id == patX ; // can't jump or already on the right element
278
+ }
283
279
284
- return true ; // we know x exists because we are using
280
+ if (x >= id ) {
281
+ return id == x ;
285
282
}
286
- case PREDICATE -> {
287
- if (patY != 0 ) {
288
- return id == patY ; // can't jump or already on the right element
289
- }
290
283
291
- if (posY == nextY ) {
292
- return false ; // no next element
293
- }
284
+ x = id ;
285
+ posY = adjY .find (x - 1 );
286
+ posZ = adjZ .find (posY );
287
+ y = adjY .get (posY );
288
+ nextY = adjY .last (x - 1 ) + 1 ;
289
+ nextZ = adjZ .find (posY + 1 );
294
290
295
- long curr = this .adjY .get (posY );
291
+ return true ; // we know x exists
292
+ }
293
+ case PREDICATE -> {
294
+ if (patY != 0 ) {
295
+ return id == patY ; // can't jump or already on the right element
296
+ }
296
297
297
- if (curr >= id ) {
298
- return curr == id ;
299
- }
300
- if (posY + 1 == nextY ) {
301
- return false ; // no next element
302
- }
298
+ if (posY == nextY ) {
299
+ return false ; // no next element
300
+ }
303
301
304
- long last = this .adjY .get (nextY - 1 );
302
+ long curr = this .adjY .get (posY );
305
303
304
+ if (curr >= id ) {
305
+ return curr == id ;
306
+ }
306
307
307
- boolean res ;
308
+ boolean res ;
309
+ if (posY + 1 == nextY ) {
310
+ // no next element, go next X
311
+ x ++;
312
+ posY = nextY ;
313
+ nextY = adjY .findNext (posY ) + 1 ;
314
+ y = adjY .get (posY );
315
+
316
+ res = false ;
317
+ } else {
318
+ long last = this .adjY .get (nextY - 1 );
308
319
309
320
if (last > id ) {
310
321
// binary search between curr <-> last id
@@ -319,77 +330,79 @@ private boolean gotoOrder(long id, TripleComponentRole role) {
319
330
posY = -loc - 1 ;
320
331
y = adjY .get (posY );
321
332
}
322
- } else if (last != id ) {
323
- // last < id - GOTO end + 1
324
- posY = nextY ;
325
- res = false ;
326
333
} else {
327
- // last == id - GOTO last
328
- posY = nextY - 1 ;
329
- y = adjY .get (posY );
330
- res = true ;
334
+ if (last != id ) {
335
+ // last < id - GOTO end + 1
336
+ posY = nextY ;
337
+ res = false ;
338
+ } else {
339
+ // last == id - GOTO last
340
+ posY = nextY - 1 ;
341
+ y = adjY .get (posY );
342
+ res = true ;
343
+ }
344
+ nextY = adjY .findNext (posY ) + 1 ;
331
345
}
346
+ }
332
347
333
- nextY = adjY .findNext (posY ) + 1 ;
334
-
335
- // down to z/posZ/nextZ?
336
- posZ = adjZ .find (posY , patZ );
337
- nextZ = adjZ .findNext (posZ ) + 1 ;
348
+ // down to z/posZ/nextZ?
349
+ posZ = adjZ .find (posY ); // assert patZ != 0
350
+ nextZ = adjZ .findNext (posZ ) + 1 ;
338
351
339
- return res ;
352
+ return res ;
353
+ }
354
+ case OBJECT -> {
355
+ if (patZ != 0 ) {
356
+ return id == patZ ; // can't jump or already on the right element
340
357
}
341
- case OBJECT -> {
342
- if (patZ != 0 ) {
343
- return id == patZ ; // can't jump or already on the right element
344
- }
345
358
346
- if (posZ == nextZ ) {
347
- return false ; // no next element
348
- }
349
-
350
- long curr = this .adjZ .get (posZ );
359
+ if (posZ == nextZ ) {
360
+ return false ; // no next element
361
+ }
351
362
352
- if (curr >= id ) {
353
- return curr == id ;
354
- }
355
- if (posZ + 1 == nextZ ) {
356
- return false ; // no next element
357
- }
363
+ long curr = this .adjZ .get (posZ );
358
364
359
- long last = this .adjZ .get (nextZ - 1 );
365
+ if (curr >= id ) {
366
+ return curr == id ;
367
+ }
368
+ if (posZ + 1 == nextZ ) {
369
+ return false ; // no next element
370
+ }
360
371
372
+ long last = this .adjZ .get (nextZ - 1 );
361
373
362
- boolean res ;
374
+ boolean res ;
363
375
364
- if (last > id ) {
365
- // binary search between curr <-> last id
366
- long loc = this .adjZ .searchLoc (id , posZ + 1 , nextZ - 2 );
376
+ if (last > id ) {
377
+ // binary search between curr <-> last id
378
+ long loc = this .adjZ .searchLoc (id , posZ + 1 , nextZ - 2 );
367
379
368
- if (loc >= 0 ) { //match
369
- res = true ;
370
- posZ = loc ;
371
- //z = id; // no need to compute the z, it is only used in next()
372
- } else {
373
- res = false ;
374
- posZ = -loc - 1 ;
375
- //z = adjZ.get(posZ);
376
- }
377
- } else if (last != id ) {
378
- // last < id - GOTO end
379
- posZ = nextZ ;
380
- res = false ;
381
- } else {
382
- // last == id - GOTO last
383
- posZ = nextZ - 1 ;
384
- //z = adjZ.get(posZ);
380
+ if (loc >= 0 ) { // match
385
381
res = true ;
382
+ posZ = loc ;
383
+ // z = id; // no need to compute the z, it is only used in
384
+ // next()
385
+ } else {
386
+ res = false ;
387
+ posZ = -loc - 1 ;
388
+ // z = adjZ.get(posZ);
386
389
}
390
+ } else if (last != id ) {
391
+ // last < id - GOTO end
392
+ posZ = nextZ ;
393
+ res = false ;
394
+ } else {
395
+ // last == id - GOTO last
396
+ posZ = nextZ - 1 ;
397
+ // z = adjZ.get(posZ);
398
+ res = true ;
399
+ }
387
400
388
- nextZ = adjZ .findNext (posZ ) + 1 ;
401
+ nextZ = adjZ .findNext (posZ ) + 1 ;
389
402
390
- return res ;
391
- }
392
- default -> throw new NotImplementedException ("goto " + role );
403
+ return res ;
404
+ }
405
+ default -> throw new NotImplementedException ("goto " + role );
393
406
}
394
407
}
395
408
@@ -402,6 +415,7 @@ public boolean gotoSubject(long id) {
402
415
public boolean gotoPredicate (long id ) {
403
416
return gotoOrder (id , idx .getOrder ().getPredicateMapping ());
404
417
}
418
+
405
419
@ Override
406
420
public boolean gotoObject (long id ) {
407
421
return gotoOrder (id , idx .getOrder ().getObjectMapping ());
@@ -411,10 +425,12 @@ public boolean gotoObject(long id) {
411
425
public boolean canGoToSubject () {
412
426
return true ;
413
427
}
428
+
414
429
@ Override
415
430
public boolean canGoToPredicate () {
416
431
return true ;
417
432
}
433
+
418
434
@ Override
419
435
public boolean canGoToObject () {
420
436
return true ;
0 commit comments