MCPcopy Create free account
hub / github.com/BaseXdb/basex / iterative

Method iterative

basex-core/src/main/java/org/basex/query/expr/path/Path.java:447–497  ·  view source on GitHub ↗

Checks if a path can be evaluated iteratively (i.e., if all results will be in distinct document order without final sorting). @param root root expression (can be null) @param steps path steps @return result of check

(final Expr root, final Expr... steps)

Source from the content-addressed store, hash-verified

445 * @return result of check
446 */
447 private static boolean iterative(final Expr root, final Expr... steps) {
448 if(root == null || !root.ddo()) return false;
449
450 final SeqType st = root.seqType();
451 boolean atMostOne = st.zeroOrOne();
452 boolean sameDepth = atMostOne || st.type.instanceOf(NodeType.DOCUMENT);
453
454 for(final Expr expr : steps) {
455 final Step step = (Step) expr;
456 switch(step.axis) {
457 case ATTRIBUTE:
458 case SELF:
459 // nothing changes
460 break;
461 case PARENT:
462 case FOLLOWING_SIBLING:
463 case FOLLOWING_SIBLING_OR_SELF:
464 // can overlap, preserves level
465 if(!atMostOne) return false;
466 break;
467 case CHILD:
468 // order is only ensured if all nodes are on the same level
469 if(!sameDepth) return false;
470 break;
471 case DESCENDANT:
472 case DESCENDANT_OR_SELF:
473 // non-overlapping if all nodes are on the same level
474 if(!sameDepth) return false;
475 sameDepth = false;
476 break;
477 case ANCESTOR:
478 case ANCESTOR_OR_SELF:
479 case PRECEDING:
480 case PRECEDING_OR_SELF:
481 case PRECEDING_SIBLING:
482 case PRECEDING_SIBLING_OR_SELF:
483 // backwards axes must be reordered
484 return false;
485 case FOLLOWING:
486 case FOLLOWING_OR_SELF:
487 // can overlap
488 if(!atMostOne) return false;
489 sameDepth = false;
490 break;
491 default:
492 throw Util.notExpected();
493 }
494 atMostOne &= step.seqType().zeroOrOne();
495 }
496 return true;
497 }
498
499 /**
500 * Assigns a sequence type and (if statically known) result size.

Callers 1

getMethod · 0.95

Calls 6

zeroOrOneMethod · 0.95
notExpectedMethod · 0.95
seqTypeMethod · 0.95
seqTypeMethod · 0.65
instanceOfMethod · 0.65
ddoMethod · 0.45

Tested by

no test coverage detected