You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2010/11/26 15:36:11 UTC
svn commit: r1039382 - in
/lucene/dev/trunk/lucene/src/java/org/apache/lucene:
index/codecs/FixedGapTermsIndexReader.java
search/cache/DocTermsCreator.java search/cache/DocTermsIndexCreator.java
util/PagedBytes.java
Author: simonw
Date: Fri Nov 26 14:36:10 2010
New Revision: 1039382
URL: http://svn.apache.org/viewvc?rev=1039382&view=rev
Log:
LUCENE-2777: Revise PagedBytes#fillUsingLengthPrefix* methods names
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/PagedBytes.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java?rev=1039382&r1=1039381&r2=1039382&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/FixedGapTermsIndexReader.java Fri Nov 26 14:36:10 2010
@@ -358,7 +358,7 @@ public class FixedGapTermsIndexReader ex
private void fillResult(int idx, TermsIndexResult result) {
final long offset = termOffsets.get(idx);
final int length = (int) (termOffsets.get(1+idx) - offset);
- termBytesReader.fill(result.term, termBytesStart + offset, length);
+ termBytesReader.fillSlice(result.term, termBytesStart + offset, length);
result.position = idx * totalIndexInterval;
result.offset = termsStart + termsDictOffsets.get(idx);
}
@@ -373,7 +373,7 @@ public class FixedGapTermsIndexReader ex
final long offset = termOffsets.get(mid);
final int length = (int) (termOffsets.get(1+mid) - offset);
- termBytesReader.fill(result.term, termBytesStart + offset, length);
+ termBytesReader.fillSlice(result.term, termBytesStart + offset, length);
int delta = termComp.compare(term, result.term);
if (delta < 0) {
@@ -394,7 +394,7 @@ public class FixedGapTermsIndexReader ex
final long offset = termOffsets.get(hi);
final int length = (int) (termOffsets.get(1+hi) - offset);
- termBytesReader.fill(result.term, termBytesStart + offset, length);
+ termBytesReader.fillSlice(result.term, termBytesStart + offset, length);
result.position = hi*totalIndexInterval;
result.offset = termsStart + termsDictOffsets.get(hi);
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java?rev=1039382&r1=1039381&r2=1039382&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsCreator.java Fri Nov 26 14:36:10 2010
@@ -165,7 +165,7 @@ public class DocTermsCreator extends Ent
@Override
public BytesRef getTerm(int docID, BytesRef ret) {
final long pointer = docToOffset.get(docID);
- return bytes.fillUsingLengthPrefix(ret, pointer);
+ return bytes.fill(ret, pointer);
}
}
}
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java?rev=1039382&r1=1039381&r2=1039382&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/cache/DocTermsIndexCreator.java Fri Nov 26 14:36:10 2010
@@ -213,7 +213,7 @@ public class DocTermsIndexCreator extend
@Override
public BytesRef lookup(int ord, BytesRef ret) {
- return bytes.fillUsingLengthPrefix(ret, termOrdToBytesOffset.get(ord));
+ return bytes.fill(ret, termOrdToBytesOffset.get(ord));
}
@Override
@@ -235,7 +235,7 @@ public class DocTermsIndexCreator extend
currentBlockNumber = 0;
blocks = bytes.getBlocks();
blockEnds = bytes.getBlockEnds();
- currentBlockNumber = bytes.fillUsingLengthPrefix2(term, termOrdToBytesOffset.get(0));
+ currentBlockNumber = bytes.fillAndGetIndex(term, termOrdToBytesOffset.get(0));
end = blockEnds[currentBlockNumber];
}
@@ -249,7 +249,7 @@ public class DocTermsIndexCreator extend
public SeekStatus seek(long ord) throws IOException {
assert(ord >= 0 && ord <= numOrd);
// TODO: if gap is small, could iterate from current position? Or let user decide that?
- currentBlockNumber = bytes.fillUsingLengthPrefix2(term, termOrdToBytesOffset.get((int)ord));
+ currentBlockNumber = bytes.fillAndGetIndex(term, termOrdToBytesOffset.get((int)ord));
end = blockEnds[currentBlockNumber];
currentOrd = (int)ord;
return SeekStatus.FOUND;
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/PagedBytes.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/PagedBytes.java?rev=1039382&r1=1039381&r2=1039382&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/PagedBytes.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/PagedBytes.java Fri Nov 26 14:36:10 2010
@@ -29,7 +29,8 @@ import java.io.IOException;
* using copy, and then retrieve slices (BytesRef) into it
* using fill.
*
- * <p>@lucene.internal</p>*/
+ * @lucene.internal
+ **/
public final class PagedBytes {
private final List<byte[]> blocks = new ArrayList<byte[]>();
private final List<Integer> blockEnd = new ArrayList<Integer>();
@@ -63,8 +64,16 @@ public final class PagedBytes {
blockSize = pagedBytes.blockSize;
}
- /** Get a slice out of the byte array. */
- public BytesRef fill(BytesRef b, long start, int length) {
+ /**
+ * Gets a slice out of {@link PagedBytes} starting at <i>start</i> with a
+ * given length. Iff the slice spans across a block border this method will
+ * allocate sufficient resources and copy the paged data.
+ * <p>
+ * Slices spanning more than one block are not supported.
+ * </p>
+ * @lucene.internal
+ **/
+ public BytesRef fillSlice(BytesRef b, long start, int length) {
assert length >= 0: "length=" + length;
final int index = (int) (start >> blockBits);
final int offset = (int) (start & blockMask);
@@ -91,8 +100,18 @@ public final class PagedBytes {
return b;
}
- /** Reads length as 1 or 2 byte vInt prefix, starting @ start */
- public BytesRef fillUsingLengthPrefix(BytesRef b, long start) {
+ /**
+ * Reads length as 1 or 2 byte vInt prefix, starting at <i>start</i>.
+ * <p>
+ * <b>Note:</b> this method does not support slices spanning across block
+ * borders.
+ * </p>
+ *
+ * @return the given {@link BytesRef}
+ *
+ * @lucene.internal
+ **/
+ public BytesRef fill(BytesRef b, long start) {
final int index = (int) (start >> blockBits);
final int offset = (int) (start & blockMask);
final byte[] block = b.bytes = blocks[index];
@@ -108,8 +127,17 @@ public final class PagedBytes {
return b;
}
- /** @lucene.internal Reads length as 1 or 2 byte vInt prefix, starting @ start. Returns the block number of the term. */
- public int fillUsingLengthPrefix2(BytesRef b, long start) {
+ /**
+ * Reads length as 1 or 2 byte vInt prefix, starting at <i>start</i>. *
+ * <p>
+ * <b>Note:</b> this method does not support slices spanning across block
+ * borders.
+ * </p>
+ *
+ * @return the internal block number of the slice.
+ * @lucene.internal
+ **/
+ public int fillAndGetIndex(BytesRef b, long start) {
final int index = (int) (start >> blockBits);
final int offset = (int) (start & blockMask);
final byte[] block = b.bytes = blocks[index];
@@ -125,10 +153,21 @@ public final class PagedBytes {
return index;
}
- /** @lucene.internal Reads length as 1 or 2 byte vInt prefix, starting @ start.
- * Returns the start offset of the next part, suitable as start parameter on next call
- * to sequentially read all BytesRefs. */
- public long fillUsingLengthPrefix3(BytesRef b, long start) {
+ /**
+ * Reads length as 1 or 2 byte vInt prefix, starting at <i>start</i> and
+ * returns the start offset of the next part, suitable as start parameter on
+ * next call to sequentially read all {@link BytesRef}.
+ *
+ * <p>
+ * <b>Note:</b> this method does not support slices spanning across block
+ * borders.
+ * </p>
+ *
+ * @return the start offset of the next part, suitable as start parameter on
+ * next call to sequentially read all {@link BytesRef}.
+ * @lucene.internal
+ **/
+ public long fillAndGetStart(BytesRef b, long start) {
final int index = (int) (start >> blockBits);
final int offset = (int) (start & blockMask);
final byte[] block = b.bytes = blocks[index];