Index: lucene/suggest/src/test/org/apache/lucene/search/suggest/TestBytesRefArray.java =================================================================== --- lucene/suggest/src/test/org/apache/lucene/search/suggest/TestBytesRefArray.java (revision 1458959) +++ lucene/suggest/src/test/org/apache/lucene/search/suggest/TestBytesRefArray.java (working copy) @@ -39,11 +39,12 @@ } int entries = atLeast(500); BytesRef spare = new BytesRef(); + int initSize = list.size(); for (int i = 0; i < entries; i++) { String randomRealisticUnicodeString = _TestUtil .randomRealisticUnicodeString(random); spare.copyChars(randomRealisticUnicodeString); - list.append(spare); + assertEquals(i+initSize, list.append(spare)); stringList.add(randomRealisticUnicodeString); } for (int i = 0; i < entries; i++) { @@ -81,11 +82,12 @@ } int entries = atLeast(500); BytesRef spare = new BytesRef(); + final int initSize = list.size(); for (int i = 0; i < entries; i++) { String randomRealisticUnicodeString = _TestUtil .randomRealisticUnicodeString(random); spare.copyChars(randomRealisticUnicodeString); - list.append(spare); + assertEquals(initSize + i, list.append(spare)); stringList.add(randomRealisticUnicodeString); } Index: lucene/suggest/src/java/org/apache/lucene/search/suggest/BytesRefArray.java =================================================================== --- lucene/suggest/src/java/org/apache/lucene/search/suggest/BytesRefArray.java (revision 1458959) +++ lucene/suggest/src/java/org/apache/lucene/search/suggest/BytesRefArray.java (working copy) @@ -70,7 +70,7 @@ /** * Appends a copy of the given {@link BytesRef} to this {@link BytesRefArray}. * @param bytes the bytes to append - * @return the ordinal of the appended bytes + * @return the index of the appended bytes */ public int append(BytesRef bytes) { if (lastElement >= offsets.length) { @@ -82,7 +82,7 @@ pool.append(bytes); offsets[lastElement++] = currentOffset; currentOffset += bytes.length; - return lastElement; + return lastElement-1; } /** @@ -96,21 +96,21 @@ /** * Returns the n'th element of this {@link BytesRefArray} * @param spare a spare {@link BytesRef} instance - * @param ord the elements ordinal to retrieve + * @param index the elements index to retrieve * @return the n'th element of this {@link BytesRefArray} */ - public BytesRef get(BytesRef spare, int ord) { - if (lastElement > ord) { - int offset = offsets[ord]; - int length = ord == lastElement - 1 ? currentOffset - offset - : offsets[ord + 1] - offset; + public BytesRef get(BytesRef spare, int index) { + if (lastElement > index) { + int offset = offsets[index]; + int length = index == lastElement - 1 ? currentOffset - offset + : offsets[index + 1] - offset; assert spare.offset == 0; spare.grow(length); spare.length = length; pool.readBytes(offset, spare.bytes, spare.offset, spare.length); return spare; } - throw new IndexOutOfBoundsException("index " + ord + throw new IndexOutOfBoundsException("index " + index + " must be less than the size: " + lastElement); } @@ -130,20 +130,20 @@ @Override protected int compare(int i, int j) { - final int ord1 = orderedEntries[i], ord2 = orderedEntries[j]; - return comp.compare(get(scratch1, ord1), get(scratch2, ord2)); + final int idx1 = orderedEntries[i], idx2 = orderedEntries[j]; + return comp.compare(get(scratch1, idx1), get(scratch2, idx2)); } @Override protected void setPivot(int i) { - final int ord = orderedEntries[i]; - get(pivot, ord); + final int index = orderedEntries[i]; + get(pivot, index); } @Override protected int comparePivot(int j) { - final int ord = orderedEntries[j]; - return comp.compare(pivot, get(scratch2, ord)); + final int index = orderedEntries[j]; + return comp.compare(pivot, get(scratch2, index)); } private final BytesRef pivot = new BytesRef(), scratch1 = new BytesRef(), @@ -176,14 +176,14 @@ public BytesRefIterator iterator(final Comparator comp) { final BytesRef spare = new BytesRef(); final int size = size(); - final int[] ords = comp == null ? null : sort(comp); + final int[] indices = comp == null ? null : sort(comp); return new BytesRefIterator() { int pos = 0; @Override public BytesRef next() { if (pos < size) { - return get(spare, ords == null ? pos++ : ords[pos++]); + return get(spare, indices == null ? pos++ : indices[pos++]); } return null; }