コード例 #1
0
ファイル: ANode.java プロジェクト: fpapai/basex
 /**
  * Compares two nodes for their unique order.
  *
  * @param node1 first node
  * @param node2 node to be compared
  * @return {@code 0} if the nodes are identical, or {@code 1}/{@code -1} if the first node appears
  *     after/before the second
  */
 static int diff(final ANode node1, final ANode node2) {
   // cache parents of first node
   final ANodeList nl = new ANodeList();
   for (ANode n = node1; n != null; n = n.parent()) {
     if (n == node2) return 1;
     nl.add(n);
   }
   // find lowest common ancestor
   ANode c2 = node2;
   LOOP:
   for (ANode n = node2; (n = n.parent()) != null; ) {
     final int is = nl.size();
     for (int i = 1; i < is; i++) {
       if (n == node1) return -1;
       if (!nl.get(i).is(n)) continue;
       // check which node appears as first LCA child
       final ANode c1 = nl.get(i - 1);
       final BasicNodeIter ir = n.children();
       for (ANode c; (c = ir.next()) != null; ) {
         if (c.is(c1)) return -1;
         if (c.is(c2)) return 1;
       }
       break LOOP;
     }
     c2 = n;
   }
   // subtraction is used instead of comparison to support overflow of node id
   return node1.id - node2.id < 0 ? -1 : 1;
 }
コード例 #2
0
ファイル: Except.java プロジェクト: james-jw/basex
  @Override
  protected ANodeList eval(final Iter[] iter) throws QueryException {
    final ANodeList list = new ANodeList().check();

    for (Item it; (it = iter[0].next()) != null; ) list.add(toNode(it));
    final boolean db = list.dbnodes();

    final int el = exprs.length;
    for (int e = 1; e < el && !list.isEmpty(); e++) {
      final Iter ir = iter[e];
      for (Item it; (it = ir.next()) != null; ) {
        final int i = list.indexOf(toNode(it), db);
        if (i != -1) list.delete(i);
      }
    }
    return list;
  }
コード例 #3
0
ファイル: ANode.java プロジェクト: fpapai/basex
 /**
  * Adds children of a sub node.
  *
  * @param ch child nodes
  * @param nb node cache
  */
 static void addDesc(final BasicNodeIter ch, final ANodeList nb) {
   for (ANode n; (n = ch.next()) != null; ) {
     nb.add(n.finish());
     addDesc(n.children(), nb);
   }
 }