Refine search
/** * Used to grow the reference array. */ public void grow(int newLength) { ref.chars = ArrayUtil.grow(ref.chars, newLength); }
/** Create a {@link GrowableByteArrayDataOutput} with the given initial capacity. */ public GrowableByteArrayDataOutput(int cp) { this.bytes = new byte[ArrayUtil.oversize(cp, 1)]; this.length = 0; }
/** * Sorts the given array using the {@link Comparator}. This method uses the Tim sort * algorithm, but falls back to binary sort for small arrays. */ public static <T> void timSort(T[] a, Comparator<? super T> comp) { timSort(a, 0, a.length, comp); }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static short[] grow(short[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { return growExact(array, oversize(minSize, Short.BYTES)); } else return array; }
@Override public int[] grow() { final int[] ord = super.grow(); boost = ArrayUtil.grow(boost, ord.length); if (termState.length < ord.length) { TermContext[] tmpTermState = new TermContext[ArrayUtil.oversize(ord.length, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.arraycopy(termState, 0, tmpTermState, 0, termState.length); termState = tmpTermState; } assert termState.length >= ord.length && boost.length >= ord.length; return ord; }
BytesRefBuilder scratch = new BytesRefBuilder(); if (scratch.length() > Short.MAX_VALUE-2) { throw new IllegalArgumentException( "cannot handle analyzed forms > " + (Short.MAX_VALUE-2) + " in length (got " + scratch.length() + ")"); short analyzedLength = (short) scratch.length(); buffer = ArrayUtil.grow(buffer, requiredLength);
Map<String,Integer> seenStrips) throws IOException, ParseException { BytesRefBuilder scratch = new BytesRefBuilder(); StringBuilder sb = new StringBuilder(); String args[] = header.split("\\s+"); affixData = ArrayUtil.grow(affixData, (currentAffix << 3) + (numLines << 3)); ByteArrayDataOutput affixWriter = new ByteArrayDataOutput(affixData, currentAffix << 3, numLines << 3); int appendFlagsOrd = flagLookup.add(scratch.get()); if (appendFlagsOrd < 0) {
public void finishTerm(long defaultWeight) throws IOException { ArrayUtil.timSort(surfaceFormsAndPayload, 0, count); int deduplicator = 0; analyzed.append((byte) 0); analyzed.setLength(analyzed.length() + 1); analyzed.grow(analyzed.length()); for (int i = 0; i < count; i++) { analyzed.setByteAt(analyzed.length() - 1, (byte) deduplicator++); Util.toIntsRef(analyzed.get(), scratchInts); SurfaceFormAndPayload candiate = surfaceFormsAndPayload[i]; long cost = candiate.weight == -1 ? encodeWeight(Math.min(Integer.MAX_VALUE, defaultWeight)) : candiate.weight; builder.add(scratchInts.get(), outputs.newPair(cost, candiate.payload)); } seenSurfaceForms.clear(); count = 0; }
/** * Creates a new {@link TermInSetQuery} from the given collection of terms. */ public TermInSetQuery(String field, Collection<BytesRef> terms) { BytesRef[] sortedTerms = terms.toArray(new BytesRef[terms.size()]); // already sorted if we are a SortedSet with natural order boolean sorted = terms instanceof SortedSet && ((SortedSet<BytesRef>)terms).comparator() == null; if (!sorted) { ArrayUtil.timSort(sortedTerms); } PrefixCodedTerms.Builder builder = new PrefixCodedTerms.Builder(); BytesRefBuilder previous = null; for (BytesRef term : sortedTerms) { if (previous == null) { previous = new BytesRefBuilder(); } else if (previous.get().equals(term)) { continue; // deduplicate } builder.add(field, term); previous.copyBytes(term); } this.field = field; termData = builder.finish(); termDataHashCode = termData.hashCode(); }
/** * Make sure the {@link #values} array can store at least {@link #count} entries. */ protected final void grow() { if (values.length < count) { final int oldLen = values.length; final int newLen = ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF); values = Arrays.copyOf(values, newLen); for (int i = oldLen; i < newLen; ++i) { values[i] = new BytesRefBuilder(); } } }
/** Pushes the new term to the top of the stack, and writes new blocks. */ private void pushTerm(BytesRef text) throws IOException { int limit = Math.min(lastTerm.length(), text.length); // Find common prefix between last term and current term: int pos = 0; while (pos < limit && lastTerm.byteAt(pos) == text.bytes[text.offset+pos]) { pos++; } // if (DEBUG) System.out.println(" shared=" + pos + " lastTerm.length=" + lastTerm.length); // Close the "abandoned" suffix now: for(int i=lastTerm.length()-1;i>=pos;i--) { // How many items on top of the stack share the current suffix // we are closing: int prefixTopSize = pending.size() - prefixStarts[i]; if (prefixTopSize >= minItemsInBlock) { // if (DEBUG) System.out.println("pushTerm i=" + i + " prefixTopSize=" + prefixTopSize + " minItemsInBlock=" + minItemsInBlock); writeBlocks(i+1, prefixTopSize); prefixStarts[i] -= prefixTopSize-1; } } if (prefixStarts.length < text.length) { prefixStarts = ArrayUtil.grow(prefixStarts, text.length); } // Init new tail: for(int i=pos;i<text.length;i++) { prefixStarts[i] = pending.size(); } lastTerm.copyBytes(text); }
if (readPositions) { SimpleTextUtil.readLine(in, scratch); assert StringHelper.startsWith(scratch.get(), POS): "got line=" + scratch.get().utf8ToString(); scratchUTF16_2.copyUTF8Bytes(scratch.bytes(), POS.length, scratch.length()-POS.length); pos = ArrayUtil.parseInt(scratchUTF16_2.chars(), 0, scratchUTF16_2.length()); } else { pos = -1; assert StringHelper.startsWith(scratch.get(), START_OFFSET): "got line=" + scratch.get().utf8ToString(); scratchUTF16_2.copyUTF8Bytes(scratch.bytes(), START_OFFSET.length, scratch.length()-START_OFFSET.length); startOffset = ArrayUtil.parseInt(scratchUTF16_2.chars(), 0, scratchUTF16_2.length()); SimpleTextUtil.readLine(in, scratch); assert StringHelper.startsWith(scratch.get(), END_OFFSET): "got line=" + scratch.get().utf8ToString(); scratchUTF16_2.grow(scratch.length()-END_OFFSET.length); scratchUTF16_2.copyUTF8Bytes(scratch.bytes(), END_OFFSET.length, scratch.length()-END_OFFSET.length); endOffset = ArrayUtil.parseInt(scratchUTF16_2.chars(), 0, scratchUTF16_2.length());
/** * Set the {@link #size()} and ensure that the {@link #values} array can * store at least that many entries. */ protected void resize(int newSize) { count = newSize; if (newSize > values.length) { final int oldLength = values.length; values = ArrayUtil.grow(values, count); for (int i = oldLength; i < values.length; ++i) { values[i] = new BytesRefBuilder(); } } }
@Override protected void swap(int i, int j) { ArrayUtil.swap(arr, i, j); }
ArrayUtil.timSort(scoreTerms, scoreTermSortByTermComp); final Term term = new Term(query.field, st.bytes.toBytesRef());
/** * Parses a char array into an int. * @param chars the character array * @param offset The offset into the array * @param len The length * @return the int * @throws NumberFormatException if it can't parse */ public static int parseInt(char[] chars, int offset, int len) throws NumberFormatException { return parseInt(chars, offset, len, 10); }
@Override public int hashCode() { int code = termLength; code = code * 31 + ArrayUtil.hashCode(termBuffer, 0, termLength); return code; }
BytesRefBuilder flagsScratch = new BytesRefBuilder(); IntsRefBuilder scratchInts = new IntsRefBuilder(); String stemException = parseStemException(line.substring(end+1)); if (stemException != null) { stemExceptions = ArrayUtil.grow(stemExceptions, stemExceptionCount+1); stemExceptionID = stemExceptionCount+1; // we use '0' to indicate no exception for the form stemExceptions[stemExceptionCount++] = stemException; } else { encodeFlags(flagsScratch, wordForm); int ord = flagLookup.add(flagsScratch.get()); if (ord < 0) {
/** * Make sure the {#values} array can store at least {#count} entries. */ protected final void grow() { if (values.length < count) { final int oldLen = values.length; final int newLen = ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF); values = Arrays.copyOf(values, newLen); for (int i = oldLen; i < newLen; ++i) { values[i] = new BytesRefBuilder(); } } }