You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2012/07/04 10:17:04 UTC
svn commit: r1357159 [1/4] - in /lucene/dev/trunk/lucene/core/src:
java/org/apache/lucene/codecs/
java/org/apache/lucene/codecs/lucene40/values/ java/org/apache/lucene/util/
java/org/apache/lucene/util/packed/ test/org/apache/lucene/util/packed/
Author: jpountz
Date: Wed Jul 4 08:17:02 2012
New Revision: 1357159
URL: http://svn.apache.org/viewvc?rev=1357159&view=rev
Log:
LUCENE-4161: Make packed int arrays usable by codecs.
Added:
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/LongsRef.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/gen_BulkOperation.py
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/gen_Direct.py
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/gen_PackedThreeBlocks.py
Removed:
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Packed64SingleBlockReaderIterator.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Packed64SingleBlockWriter.java
Modified:
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/FixedGapTermsIndexReader.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Direct16.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Direct32.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Direct64.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Direct8.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Packed16ThreeBlocks.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Packed64.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Packed64SingleBlock.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/Packed8ThreeBlocks.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/PackedReaderIterator.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/PackedWriter.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/gen_Packed64SingleBlock.py
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/packed/package.html
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/FixedGapTermsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/FixedGapTermsIndexReader.java?rev=1357159&r1=1357158&r2=1357159&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/FixedGapTermsIndexReader.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/FixedGapTermsIndexReader.java Wed Jul 4 08:17:02 2012
@@ -315,10 +315,10 @@ public class FixedGapTermsIndexReader ex
try {
// Subsample the index terms
clone1.seek(packedIndexStart);
- final PackedInts.ReaderIterator termsDictOffsetsIter = PackedInts.getReaderIterator(clone1);
+ final PackedInts.ReaderIterator termsDictOffsetsIter = PackedInts.getReaderIterator(clone1, PackedInts.DEFAULT_BUFFER_SIZE);
clone2.seek(packedOffsetsStart);
- final PackedInts.ReaderIterator termOffsetsIter = PackedInts.getReaderIterator(clone2);
+ final PackedInts.ReaderIterator termOffsetsIter = PackedInts.getReaderIterator(clone2, PackedInts.DEFAULT_BUFFER_SIZE);
// TODO: often we can get by w/ fewer bits per
// value, below.. .but this'd be more complex:
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java?rev=1357159&r1=1357158&r2=1357159&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java Wed Jul 4 08:17:02 2012
@@ -121,7 +121,7 @@ class VarStraightBytesImpl {
final IndexInput cloneIdx = reader.cloneIndex();
try {
numDataBytes = cloneIdx.readVLong();
- final ReaderIterator iter = PackedInts.getReaderIterator(cloneIdx);
+ final ReaderIterator iter = PackedInts.getReaderIterator(cloneIdx, PackedInts.DEFAULT_BUFFER_SIZE);
for (int i = 0; i < maxDocs; i++) {
long offset = iter.next();
++lastDocID;
Added: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/LongsRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/LongsRef.java?rev=1357159&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/LongsRef.java (added)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/LongsRef.java Wed Jul 4 08:17:02 2012
@@ -0,0 +1,167 @@
+package org.apache.lucene.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** Represents long[], as a slice (offset + length) into an
+ * existing long[]. The {@link #longs} member should never be null; use
+ * {@link #EMPTY_LONGS} if necessary.
+ *
+ * @lucene.internal */
+public final class LongsRef implements Comparable<LongsRef>, Cloneable {
+
+ public static final long[] EMPTY_LONGS = new long[0];
+
+ public long[] longs;
+ public int offset;
+ public int length;
+
+ public LongsRef() {
+ longs = EMPTY_LONGS;
+ }
+
+ public LongsRef(int capacity) {
+ longs = new long[capacity];
+ }
+
+ public LongsRef(long[] longs, int offset, int length) {
+ assert longs != null;
+ assert offset >= 0;
+ assert length >= 0;
+ assert longs.length >= offset + length;
+ this.longs = longs;
+ this.offset = offset;
+ this.length = length;
+ }
+
+ @Override
+ public LongsRef clone() {
+ return new LongsRef(longs, offset, length);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 0;
+ final long end = offset + length;
+ for(int i = offset; i < end; i++) {
+ result = prime * result + (int) (longs[i] ^ (longs[i]>>>32));
+ }
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (other instanceof LongsRef) {
+ return this.longsEquals((LongsRef) other);
+ }
+ return false;
+ }
+
+ public boolean longsEquals(LongsRef other) {
+ if (length == other.length) {
+ int otherUpto = other.offset;
+ final long[] otherInts = other.longs;
+ final long end = offset + length;
+ for(int upto=offset; upto<end; upto++,otherUpto++) {
+ if (longs[upto] != otherInts[otherUpto]) {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /** Signed int order comparison */
+ public int compareTo(LongsRef other) {
+ if (this == other) return 0;
+
+ final long[] aInts = this.longs;
+ int aUpto = this.offset;
+ final long[] bInts = other.longs;
+ int bUpto = other.offset;
+
+ final long aStop = aUpto + Math.min(this.length, other.length);
+
+ while(aUpto < aStop) {
+ long aInt = aInts[aUpto++];
+ long bInt = bInts[bUpto++];
+ if (aInt > bInt) {
+ return 1;
+ } else if (aInt < bInt) {
+ return -1;
+ }
+ }
+
+ // One is a prefix of the other, or, they are equal:
+ return this.length - other.length;
+ }
+
+ public void copyLongs(LongsRef other) {
+ if (longs.length - offset < other.length) {
+ longs = new long[other.length];
+ offset = 0;
+ }
+ System.arraycopy(other.longs, other.offset, longs, offset, other.length);
+ length = other.length;
+ }
+
+ /**
+ * Used to grow the reference array.
+ *
+ * In general this should not be used as it does not take the offset into account.
+ * @lucene.internal */
+ public void grow(int newLength) {
+ assert offset == 0;
+ if (longs.length < newLength) {
+ longs = ArrayUtil.grow(longs, newLength);
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ final long end = offset + length;
+ for(int i=offset;i<end;i++) {
+ if (i > offset) {
+ sb.append(' ');
+ }
+ sb.append(Long.toHexString(longs[i]));
+ }
+ sb.append(']');
+ return sb.toString();
+ }
+
+ /**
+ * Creates a new IntsRef that points to a copy of the longs from
+ * <code>other</code>
+ * <p>
+ * The returned IntsRef will have a length of other.length
+ * and an offset of zero.
+ */
+ public static LongsRef deepCopyOf(LongsRef other) {
+ LongsRef clone = new LongsRef();
+ clone.copyLongs(other);
+ return clone;
+ }
+}