The 0x0f seems unnecessary, will remove it. the Math.abs() is for the 
when when the hash value is negative.

As for the choice of hash value, I have not evaluated the performance of 
MD5 compared to the normal Arrays.hash. I will do this next.

On 04/15/2013 01:43 PM, James Taylor wrote:
>
> In src/main/java/com/salesforce/phoenix/schema/SaltingUtil.java:
>
> > +    public static boolean isSaltingColumn(PColumn col) {
> > +        return col.getName().getString().equals(SALTING_COLUMN_NAME);
> > +    }
> > +
> > +    public static byte[] getSaltedKey(ImmutableBytesWritable key, int bucketNum) {
> > +        byte[] keyBytes = new byte[key.getSize()];
> > +        byte saltByte = getSaltingByte(key.get(), key.getOffset() + 1, key.getSize() - 1, bucketNum);
> > +        keyBytes[0] = saltByte;
> > +        System.arraycopy(key.get(), key.getOffset() + 1, keyBytes, 1, key.getSize() - 1);
> > +        return keyBytes;
> > +    }
> > +
> > +    // Generate the bucket byte given a byte and the number of buckets.
> > +    private static byte getSaltingByte(byte[] value, int offset, int length, int bucketNum) {
> > +        HashCode digest = MD5.hashBytes(value, offset, length);
> > +        byte bucketByte = (byte) ((Math.abs(digest.asInt()) % bucketNum) & 0x0f);
>
> Why the & 0x0f ? Why not just digest.asInt() % bucketNum cast as a byte?
>
> —
> Reply to this email directly or view it on GitHub 
> <https://github.com/forcedotcom/phoenix/pull/139/files#r3801460>.
>