public void initLegacyPolicy(LinkedHashSet<String> uForests) { policy = new LegacyAssignmentPolicy(uForests); }
@Override public int getPlacementForestIndex(DocumentURI uri) { return getPlacementId(uri, forests.length); }
public static int getPlacementId(DocumentURI uri, int size) { switch (size) { case 0: throw new IllegalArgumentException("getPlacementId(size = 0)"); case 1: return 0; default: String nk = normalize(uri.getUri()); BigInteger uriKey = getUriKey(nk); long u = uriKey.longValue(); for (int i = 8; i <= 56; i += 8) { u += rotl(uriKey, i); } long v = (0xffff + size) / size; return (int) ((u & 0xffff) / v); } }
private int getBucketPlacementId(DocumentURI uri, int[][] buckets, int numBuckets, int numForests, int uForests) { String nk = LegacyAssignmentPolicy.normalize(uri.getUri()); BigInteger uriKey=LegacyAssignmentPolicy.getUriKey(nk); long u = uriKey.longValue(); for (int i = 14; i <= 56; i += 14) { u ^= uriKey.shiftRight(i).longValue(); } int bucket = (int) (u&0x3fff); int fIdx = buckets[numForests - 1][bucket]; boolean allUpdatble = numForests == uForests; if (!allUpdatble) { int[] partv = new int[uForests]; int j = 0; for (int i = 0; i < numForests; i++) { if (isUpdatable(i)) { partv[j++] = i; } } fIdx = partv[LegacyAssignmentPolicy.getPlacementId(uri, uForests)]; } return fIdx; }
public static BigInteger getUriKey(String uri) { BigInteger value = hash64(uri).multiply(BigInteger.valueOf(5)).add( URI_KEY_HASH); byte[] valueBytes = value.toByteArray(); byte[] longBytes = new byte[8]; System.arraycopy(valueBytes, valueBytes.length - longBytes.length, longBytes, 0, longBytes.length); BigInteger key = new BigInteger(1, longBytes); return key; }
/** * Assign a forest based on the URI key and the number of forests. Return * a zero-based index to the forest list. * * @param size size * @return index to the forest list. */ @Deprecated public int getPlacementId(int size) { switch (size) { case 0: throw new IllegalArgumentException("getPlacementId(size = 0)"); case 1: return 0; default: return LegacyAssignmentPolicy.getPlacementId(this, size); } }