コード例 #1
0
ファイル: FTIndex.java プロジェクト: fpapai/basex
  @Override
  public EntryIterator entries(final IndexEntries entries) {
    final byte[] prefix = entries.get();
    return new EntryIterator() {
      int ti = prefix.length - 1, i, e, nr;
      boolean inner;

      @Override
      public synchronized byte[] next() {
        if (inner && i < e) {
          // loop through all entries with the same character length
          final byte[] entry = inY.readBytes(i, ti);
          if (startsWith(entry, prefix)) {
            final long poi = inY.read5();
            nr = inY.read4();
            if (prefix.length != 0) cache.add(entry, nr, poi);
            i += ti + ENTRY;
            return entry;
          }
        }
        // find next available entry group
        final int tl = tp.length;
        while (++ti < tl - 1) {
          i = tp[ti];
          if (i == -1) continue;
          int c = ti + 1;
          do e = tp[c++];
          while (e == -1);
          nr = 0;
          inner = true;
          i = find(prefix, i, e, ti);
          // jump to inner loop
          final byte[] n = next();
          if (n != null) return n;
        }
        // all entries processed: return null
        return null;
      }

      @Override
      public int count() {
        return nr;
      }
    };
  }
コード例 #2
0
ファイル: MemValues.java プロジェクト: BaseXdb/basex
  @Override
  public EntryIterator entries(final IndexEntries entries) {
    final byte[] prefix = entries.get();
    return new EntryIterator() {
      final int s = values.size();
      int p;

      @Override
      public byte[] next() {
        while (++p <= s) {
          if (lenList.get(p) == 0) continue;
          final byte[] key = values.key(p);
          if (startsWith(key, prefix)) return key;
        }
        return null;
      }

      @Override
      public int count() {
        return lenList.get(p);
      }
    };
  }