@Override public long ramBytesUsed() { return ((index != null) ? index.ramBytesUsed() : 0); }
@Override public SortedSetDocValues getSortedSet(FieldInfo field) throws IOException { final FSTEntry entry = fsts.get(field.name); if (entry.numOrds == 0) { return DocValues.emptySortedSet(); // empty FST! } FST<Long> instance; synchronized (this) { instance = fstInstances.get(field.name); if (instance == null) { data.seek(entry.offset); instance = new FST<>(data, PositiveIntOutputs.getSingleton()); if (!merging) { ramBytesUsed.addAndGet(instance.ramBytesUsed()); fstInstances.put(field.name, instance); } } } final BinaryDocValues docToOrds = getBinary(field); final FST<Long> fst = instance; // per-thread resources final BytesReader in = fst.getBytesReader(); final Arc<Long> firstArc = new Arc<>(); final Arc<Long> scratchArc = new Arc<>(); final IntsRefBuilder scratchInts = new IntsRefBuilder(); final BytesRefFSTEnum<Long> fstEnum = new BytesRefFSTEnum<>(fst); final ByteArrayDataInput input = new ByteArrayDataInput(); return new SortedSetDocValues() { final BytesRefBuilder term = new BytesRefBuilder(); BytesRef ordsRef; long currentOrd; @Override public long nextOrd() { if (input.eof()) { return NO_MORE_ORDS; } else { currentOrd += input.readVLong(); return currentOrd; } } @Override public void setDocument(int docID) { ordsRef = docToOrds.get(docID); input.reset(ordsRef.bytes, ordsRef.offset, ordsRef.length); currentOrd = 0; } @Override public BytesRef lookupOrd(long ord) { try { in.setPosition(0); fst.getFirstArc(firstArc); IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts); term.grow(output.length); term.clear(); return Util.toBytesRef(output, term); } catch (IOException bogus) { throw new RuntimeException(bogus); } } @Override public long lookupTerm(BytesRef key) { try { InputOutput<Long> o = fstEnum.seekCeil(key); if (o == null) { return -getValueCount() - 1; } else if (o.input.equals(key)) { return o.output.intValue(); } else { return -o.output - 1; } } catch (IOException bogus) { throw new RuntimeException(bogus); } } @Override public long getValueCount() { return entry.numOrds; } @Override public TermsEnum termsEnum() { return new FSTTermsEnum(fst); } }; }
@Override public long ramBytesUsed() { return BASE_RAM_BYTES_USED + dict.ramBytesUsed(); }
@Override public SortedDocValues getSorted(FieldInfo field) throws IOException { final FSTEntry entry = fsts.get(field.name); FST<Long> instance; synchronized (this) { instance = fstInstances.get(field.name); if (instance == null) { data.seek(entry.offset); instance = new FST<>(data, PositiveIntOutputs.getSingleton()); if (!merging) { ramBytesUsed.addAndGet(instance.ramBytesUsed()); fstInstances.put(field.name, instance); } } } final NumericDocValues docToOrd = getNumeric(field); final FST<Long> fst = instance; // per-thread resources final BytesReader in = fst.getBytesReader(); final Arc<Long> firstArc = new Arc<>(); final Arc<Long> scratchArc = new Arc<>(); final IntsRefBuilder scratchInts = new IntsRefBuilder(); final BytesRefFSTEnum<Long> fstEnum = new BytesRefFSTEnum<>(fst); return new SortedDocValues() { final BytesRefBuilder term = new BytesRefBuilder(); @Override public int getOrd(int docID) { return (int) docToOrd.get(docID); } @Override public BytesRef lookupOrd(int ord) { try { in.setPosition(0); fst.getFirstArc(firstArc); IntsRef output = Util.getByOutput(fst, ord, in, firstArc, scratchArc, scratchInts); term.grow(output.length); term.clear(); return Util.toBytesRef(output, term); } catch (IOException bogus) { throw new RuntimeException(bogus); } } @Override public int lookupTerm(BytesRef key) { try { InputOutput<Long> o = fstEnum.seekCeil(key); if (o == null) { return -getValueCount() - 1; } else if (o.input.equals(key)) { return o.output.intValue(); } else { return (int) -o.output - 1; } } catch (IOException bogus) { throw new RuntimeException(bogus); } } @Override public int getValueCount() { return (int) entry.numOrds; } @Override public TermsEnum termsEnum() { return new FSTTermsEnum(fst); } }; }