示例#1
0
 /** Finishes the index creation. */
 void finish() {
   if (reorder == null) return;
   for (int i = 1; i < reorder.size(); i++) {
     if (reorder.get(i)) Arrays.sort(idsList.get(i), 0, lenList.get(i));
   }
   reorder = null;
 }
示例#2
0
 @Override
 public void rehash() {
   super.rehash();
   final int s = size << 1;
   ids = Array.copyOf(ids, s);
   len = Arrays.copyOf(len, s);
 }
示例#3
0
 @Override
 public Expr copy(final QueryContext ctx, final VarScope scp, final IntObjMap<Var> vs) {
   final Expr[] copy = copyAll(ctx, scp, vs, expr);
   final int last = copy.length - 1;
   final Expr[] args = Arrays.copyOf(copy, last);
   final DynFuncCall call = new DynFuncCall(info, sc, updating, copy[last], args);
   if (inlinedFrom != null) call.inlinedFrom = inlinedFrom.clone();
   return copyType(call);
 }
示例#4
0
  /**
   * Scans an external ID.
   *
   * @param f full flag
   * @param r root flag
   * @return id
   * @throws IOException I/O exception
   */
  private byte[] externalID(final boolean f, final boolean r) throws IOException {
    byte[] cont = null;
    final boolean pub = consume(PUBLIC);
    if (pub || consume(SYSTEM)) {
      checkS();
      if (pub) {
        pubidLit();
        if (f) checkS();
      }
      final int qu = consume(); // [11]
      if (qu == '\'' || qu == '"') {
        int ch;
        final TokenBuilder tok = new TokenBuilder();
        while ((ch = nextChar()) != qu) tok.add(ch);
        if (!f) return null;
        final String name = string(tok.finish());
        if (!dtd && r) return cont;

        final XMLInput tin = input;
        try {
          final IO file = input.io().merge(name);
          cont = file.read();
        } catch (final IOException ex) {
          Util.debug(ex);
          // skip unknown DTDs/entities
          cont = new byte[] {'?'};
        }
        input = new XMLInput(new IOContent(cont, name));

        if (consume(XDECL)) {
          check(XML);
          s();
          if (version()) checkS();
          s();
          if (encoding() == null) error(TEXTENC);
          ch = nextChar();
          if (s(ch)) ch = nextChar();
          if (ch != '?') error(WRONGCHAR, '?', ch);
          ch = nextChar();
          if (ch != '>') error(WRONGCHAR, '>', ch);
          cont = Arrays.copyOfRange(cont, input.pos(), cont.length);
        }

        s();
        if (r) {
          extSubsetDecl();
          if (!consume((char) 0)) error(INVEND);
        }
        input = tin;
      } else {
        if (f) error(SCANQUOTE, (char) qu);
        prev(1);
      }
    }
    return cont;
  }
示例#5
0
 /**
  * Indexes the specified keys and values.
  *
  * @param key key
  * @param id id value
  * @return index position
  */
 public int index(final byte[] key, final int id) {
   int i = add(key);
   if (i > 0) {
     ids[i] = new int[] {id};
   } else {
     i = -i;
     final int l = len[i];
     if (l == ids[i].length) ids[i] = Arrays.copyOf(ids[i], l << 1);
     ids[i][l] = id;
   }
   len[i]++;
   return i;
 }
示例#6
0
  /**
   * Adds values to the index.
   *
   * @param key key to be indexed
   * @param vals sorted values
   */
  void add(final byte[] key, final int... vals) {
    // token index: add values. otherwise, reference existing values
    final int id = type == IndexType.TOKEN ? values.put(key) : values.id(key), vl = vals.length;
    // updatable index: if required, resize existing arrays
    while (idsList.size() < id + 1) idsList.add(null);
    if (lenList.size() < id + 1) lenList.set(id, 0);

    final int len = lenList.get(id), size = len + vl;
    int[] ids = idsList.get(id);
    if (ids == null) {
      ids = vals;
    } else {
      if (ids.length < size) ids = Arrays.copyOf(ids, Array.newSize(size));
      System.arraycopy(vals, 0, ids, len, vl);
      if (ids[len - 1] > vals[0]) {
        if (reorder == null) reorder = new BoolList(values.size());
        reorder.set(id, true);
      }
    }
    idsList.set(id, ids);
    lenList.set(id, size);
  }
示例#7
0
  @Override
  public Expr optimize(final QueryContext ctx, final VarScope scp) throws QueryException {
    final int ar = expr.length - 1;
    final Expr f = expr[ar];
    final Type t = f.type().type;
    if (t instanceof FuncType) {
      final FuncType ft = (FuncType) t;
      if (ft.args != null && ft.args.length != ar) throw INVARITY.get(info, f, ar);
      if (ft.ret != null) type = ft.ret;
    }

    if (f instanceof XQFunctionExpr) {
      // maps can only contain fully evaluated Values, so this is safe
      if (allAreValues() && f instanceof Map) return optPre(value(ctx), ctx);

      // try to inline the function
      if (!(f instanceof FuncItem && comesFrom((FuncItem) f)) && !updating) {
        final Expr[] args = Arrays.copyOf(expr, expr.length - 1);
        final Expr inl = ((XQFunctionExpr) f).inlineExpr(args, ctx, scp, info);
        if (inl != null) return inl;
      }
    }
    return this;
  }
示例#8
0
 @Override
 protected void rehash() {
   super.rehash();
   funcs = Arrays.copyOf(funcs, size << 1);
 }
示例#9
0
 /**
  * Returns the byte buffer.
  *
  * @return byte buffer
  */
 private byte[] buffer() {
   final byte[] bb = bp == b.length ? b : Arrays.copyOf(b, bp);
   bp = 0;
   return bb;
 }
示例#10
0
 @Override
 public void checkUp() throws QueryException {
   checkNoneUp(Arrays.copyOf(expr, expr.length - 1));
 }