@Override public void rehash() { super.rehash(); final int s = size << 1; ids = Array.copyOf(ids, s); len = Arrays.copyOf(len, s); }
@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); }
/** * 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; }
/** * 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); }
@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; }
@Override protected void rehash() { super.rehash(); funcs = Arrays.copyOf(funcs, size << 1); }
/** * 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; }
@Override public void checkUp() throws QueryException { checkNoneUp(Arrays.copyOf(expr, expr.length - 1)); }