extract another zigzag encode/decode

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1586728 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-04-11 17:55:25 +00:00
parent eb21a67619
commit 56d171f2f2
2 changed files with 4 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.store.DataInput; import org.apache.lucene.store.DataInput;
import org.apache.lucene.store.InputStreamDataInput; import org.apache.lucene.store.InputStreamDataInput;
import org.apache.lucene.util.BitUtil;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
/** /**
@ -53,8 +54,7 @@ public final class ConnectionCosts {
for (int j = 0; j < costs.length; j++) { for (int j = 0; j < costs.length; j++) {
final short[] a = costs[j]; final short[] a = costs[j];
for (int i = 0; i < a.length; i++) { for (int i = 0; i < a.length; i++) {
int raw = in.readVInt(); accum += BitUtil.zigZagDecode(in.readVInt());
accum += (raw >>> 1) ^ -(raw & 1);
a[i] = (short)accum; a[i] = (short)accum;
} }
} }

View File

@ -28,6 +28,7 @@ import org.apache.lucene.analysis.ja.dict.ConnectionCosts;
import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.store.DataOutput; import org.apache.lucene.store.DataOutput;
import org.apache.lucene.store.OutputStreamDataOutput; import org.apache.lucene.store.OutputStreamDataOutput;
import org.apache.lucene.util.BitUtil;
public final class ConnectionCostsWriter { public final class ConnectionCostsWriter {
@ -64,7 +65,7 @@ public final class ConnectionCostsWriter {
assert a.length == forwardSize; assert a.length == forwardSize;
for (int i = 0; i < a.length; i++) { for (int i = 0; i < a.length; i++) {
int delta = (int)a[i] - last; int delta = (int)a[i] - last;
out.writeVInt((delta >> 31) ^ (delta << 1)); out.writeVInt(BitUtil.zigZagEncode(delta));
last = a[i]; last = a[i];
} }
} }