diff --git a/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/ConnectionCosts.java b/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/ConnectionCosts.java index 0ca72cbb40a..48e2884cb83 100644 --- a/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/ConnectionCosts.java +++ b/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/dict/ConnectionCosts.java @@ -24,6 +24,7 @@ import java.io.InputStream; import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.store.DataInput; import org.apache.lucene.store.InputStreamDataInput; +import org.apache.lucene.util.BitUtil; import org.apache.lucene.util.IOUtils; /** @@ -53,8 +54,7 @@ public final class ConnectionCosts { for (int j = 0; j < costs.length; j++) { final short[] a = costs[j]; for (int i = 0; i < a.length; i++) { - int raw = in.readVInt(); - accum += (raw >>> 1) ^ -(raw & 1); + accum += BitUtil.zigZagDecode(in.readVInt()); a[i] = (short)accum; } } diff --git a/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsWriter.java b/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsWriter.java index 45016960ec4..2cd34fec64d 100644 --- a/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsWriter.java +++ b/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsWriter.java @@ -28,6 +28,7 @@ import org.apache.lucene.analysis.ja.dict.ConnectionCosts; import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.store.DataOutput; import org.apache.lucene.store.OutputStreamDataOutput; +import org.apache.lucene.util.BitUtil; public final class ConnectionCostsWriter { @@ -64,7 +65,7 @@ public final class ConnectionCostsWriter { assert a.length == forwardSize; for (int i = 0; i < a.length; i++) { int delta = (int)a[i] - last; - out.writeVInt((delta >> 31) ^ (delta << 1)); + out.writeVInt(BitUtil.zigZagEncode(delta)); last = a[i]; } }