Ejemplo n.º 1
0
 /**
  * Finds line and column for the specified query parser.
  *
  * @param parser parser
  */
 void pos(final InputParser parser) {
   markedCol = parser.mark;
   if (info != null) return;
   // check if line/column information has already been added
   parser.pos = Math.min(parser.mark, parser.length);
   info = new InputInfo(parser);
 }
Ejemplo n.º 2
0
  @Override
  public Value value(final QueryContext qc) throws QueryException {
    final FItem getKey = checkArity(exprs[1], 1, qc);
    final long k = Math.min(toLong(exprs[2], qc), Integer.MAX_VALUE);
    if (k < 1) return Empty.SEQ;

    final Iter iter = exprs[0].iter(qc);
    final MinHeap<Item, Item> heap =
        new MinHeap<>(
            new Comparator<Item>() {
              @Override
              public int compare(final Item it1, final Item it2) {
                try {
                  return OpV.LT.eval(it1, it2, sc.collation, sc, info) ? -1 : 1;
                } catch (final QueryException qe) {
                  throw new QueryRTException(qe);
                }
              }
            });

    try {
      for (Item it; (it = iter.next()) != null; ) {
        heap.insert(checkNoEmpty(getKey.invokeItem(qc, info, it)), it);
        if (heap.size() > k) heap.removeMin();
      }
    } catch (final QueryRTException ex) {
      throw ex.getCause();
    }

    final ValueBuilder vb = new ValueBuilder();
    while (!heap.isEmpty()) vb.addFront(heap.removeMin());
    return vb.value();
  }
Ejemplo n.º 3
0
 @Override
 void calcSize(final long[] minMax) {
   minMax[0] = Math.min(minMax[0], 1);
 }