public UnsortedTermFreqIteratorWrapper(TermFreqIterator source) throws IOException { super(source); ords = new int[entries.size()]; Random random = new Random(); for (int i = 0; i < ords.length; i++) { ords[i] = i; } for (int i = 0; i < ords.length; i++) { int randomPosition = random.nextInt(ords.length); int temp = ords[i]; ords[i] = ords[randomPosition]; ords[randomPosition] = temp; } }
public BytesRef next() throws IOException { if (++curPos < entries.size()) { entries.get(spare, curPos); return spare; } return null; }
@Override public BytesRef next() throws IOException { if (++curPos < entries.size()) { return entries.get(spare, (currentOrd = ords[curPos])); } return null; } }
/** Read in a single partition of data */ int readPartition(ByteSequencesReader reader) throws IOException { long start = System.currentTimeMillis(); final BytesRef scratch = new BytesRef(); while ((scratch.bytes = reader.read()) != null) { scratch.length = scratch.bytes.length; buffer.append(scratch); // Account for the created objects. // (buffer slots do not account to buffer size.) if (ramBufferSize.bytes < buffer.bytesUsed()) { break; } } sortInfo.readTime += (System.currentTimeMillis() - start); return buffer.size(); }
final int size = size(); final int[] ords = comp == null ? null : sort(comp); return new BytesRefIterator() {
private int[] sort(final Comparator<BytesRef> comp) { final int[] orderdEntries = new int[size()]; for (int i = 0; i < orderdEntries.length; i++) { orderdEntries[i] = i;