LUCENE-5895: fix bug (when 2nd long from xorshift was negative) causing ids to be prefixed by 16 0s

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1622351 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-09-03 20:36:08 +00:00
parent 7f31b2e0e3
commit 1eee3e4ee2
1 changed files with 5 additions and 1 deletions

View File

@ -281,8 +281,12 @@ public abstract class StringHelper {
x1 = s1 ^ s0 ^ (s1 >>> 17) ^ (s0 >>> 26); // b, c x1 = s1 ^ s0 ^ (s1 >>> 17) ^ (s0 >>> 26); // b, c
} }
// First make unsigned versions of x0, x1:
BigInteger unsignedX0 = new BigInteger(1, BigInteger.valueOf(x0).toByteArray());
BigInteger unsignedX1 = new BigInteger(1, BigInteger.valueOf(x1).toByteArray());
// Concatentate bits of x0 and x1, as unsigned 128 bit integer: // Concatentate bits of x0 and x1, as unsigned 128 bit integer:
nextId = new BigInteger(1, BigInteger.valueOf(x0).shiftLeft(64).or(BigInteger.valueOf(x1)).toByteArray()); nextId = unsignedX0.shiftLeft(64).or(unsignedX1);
} }
/** Generates a non-cryptographic globally unique id. */ /** Generates a non-cryptographic globally unique id. */