Skip to content

Commit

Permalink
Added arch specific write int/long
Browse files Browse the repository at this point in the history
  • Loading branch information
expani committed Dec 2, 2024
1 parent 702580a commit 1182119
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ public static List<DocIdEncoder> getAllExcept(
.toList();
}

public static DocIdEncoder fromClazz(Class<? extends DocIdEncoder> clazz) {
String parsedEncoderName = parsedClazzName(clazz);
return getInternal(parsedEncoderName);
}

private static DocIdEncoder getInternal(String parsedEncoderName) {
if (ENCODER_NAME_TO_INSTANCE_MAPPING.containsKey(parsedEncoderName)) {
return ENCODER_NAME_TO_INSTANCE_MAPPING.get(parsedEncoderName);
Expand Down Expand Up @@ -493,6 +488,10 @@ public void decode(IndexInput in, int start, int count, int[] docIds) throws IOE
}
}

/**
* Last fallback in org.apache.lucene.util.bkd.DocIdsWriter#writeDocIds() when no optimisation
* works
*/
class Bit32Encoder implements DocIdEncoder {

@Override
Expand All @@ -510,6 +509,7 @@ public void decode(IndexInput in, int start, int count, int[] docIds) throws IOE
}
}

/** Variation of @{@link Bit32Encoder} using readLong and writeLong methods. */
class Bit32OnlyRWLongEncoder implements DocIdEncoder {

@Override
Expand Down
22 changes: 17 additions & 5 deletions lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void writeDocIds(int[] docIds, int start, int count, DataOutput out) throws IOEx
out.writeByte(BPV_21);
int i = 0;
// See
// @org.apache.lucene.benchmark.jmh.DocIdEncodingBenchmark.DocIdEncoder.Bit21With3StepsEncoder
// @org.apache.lucene.benchmark.jmh.DocIdEncodingBenchmark$DocIdEncoder$Bit21With3StepsEncoder
if (!IS_ARCH_64) {
for (; i < count - 8; i += 9) {
long l1 =
Expand All @@ -148,8 +148,14 @@ void writeDocIds(int[] docIds, int start, int count, DataOutput out) throws IOEx
| (docIds[i + 2] & BPV_21_MASK);
out.writeLong(packedLong);
}
for (; i < count; i++) {
out.writeInt(docIds[i]);
if (IS_ARCH_64) {
for (; i < count; i++) {
out.writeInt(docIds[i]);
}
} else {
for (; i < count; i++) {
out.writeLong(docIds[i]);
}
}
} else if (max <= 0xFFFFFF) {
out.writeByte(BPV_24);
Expand Down Expand Up @@ -332,8 +338,14 @@ private void readInts21(IndexInput in, int count, int[] docIDs) throws IOExcepti
docIDs[i + 1] = (int) ((packedLong >>> 21) & BPV_21_MASK);
docIDs[i + 2] = (int) (packedLong & BPV_21_MASK);
}
for (; i < count; i++) {
docIDs[i] = in.readInt();
if (IS_ARCH_64) {
for (; i < count; i++) {
docIDs[i] = in.readInt();
}
} else {
for (; i < count; i++) {
docIDs[i] = (int) in.readLong();
}
}
}

Expand Down

0 comments on commit 1182119

Please sign in to comment.