diff --git a/src/main/java/redis/clients/jedis/util/Hashing.java b/src/main/java/redis/clients/jedis/util/Hashing.java deleted file mode 100644 index b10ff04975..0000000000 --- a/src/main/java/redis/clients/jedis/util/Hashing.java +++ /dev/null @@ -1,42 +0,0 @@ -package redis.clients.jedis.util; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * @deprecated Sharding/Sharded feature will be removed in next major release. - */ -@Deprecated -public interface Hashing { - Hashing MURMUR_HASH = new MurmurHash(); - ThreadLocal md5Holder = new ThreadLocal<>(); - - Hashing MD5 = new Hashing() { - @Override - public long hash(String key) { - return hash(SafeEncoder.encode(key)); - } - - @Override - public long hash(byte[] key) { - try { - if (md5Holder.get() == null) { - md5Holder.set(MessageDigest.getInstance("MD5")); - } - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("++++ no md5 algorithm found"); - } - MessageDigest md5 = md5Holder.get(); - - md5.reset(); - md5.update(key); - byte[] bKey = md5.digest(); - return ((long) (bKey[3] & 0xFF) << 24) | ((long) (bKey[2] & 0xFF) << 16) - | ((long) (bKey[1] & 0xFF) << 8) | (long) (bKey[0] & 0xFF); - } - }; - - long hash(String key); - - long hash(byte[] key); -} \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/util/MurmurHash.java b/src/main/java/redis/clients/jedis/util/MurmurHash.java deleted file mode 100644 index a882745bca..0000000000 --- a/src/main/java/redis/clients/jedis/util/MurmurHash.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable - * law or agreed to in writing, software distributed under the License is distributed on an "AS IS" - * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License - * for the specific language governing permissions and limitations under the License. - */ - -package redis.clients.jedis.util; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -/** - * This is a very fast, non-cryptographic hash suitable for general hash-based lookup. See - * http://murmurhash.googlepages.com/ for more details.
- *

- * The C version of MurmurHash 2.0 found at that site was ported to Java by Andrzej Bialecki (ab at - * getopt org). - *

- * @deprecated Sharding/Sharded feature will be removed in next major release. - */ -@Deprecated -public class MurmurHash implements Hashing { - /** - * Hashes bytes in an array. - * @param data The bytes to hash. - * @param seed The seed for the hash. - * @return The 32 bit hash of the bytes in question. - */ - public static int hash(byte[] data, int seed) { - return hash(ByteBuffer.wrap(data), seed); - } - - /** - * Hashes bytes in part of an array. - * @param data The data to hash. - * @param offset Where to start munging. - * @param length How many bytes to process. - * @param seed The seed to start with. - * @return The 32-bit hash of the data in question. - */ - public static int hash(byte[] data, int offset, int length, int seed) { - return hash(ByteBuffer.wrap(data, offset, length), seed); - } - - /** - * Hashes the bytes in a buffer from the current position to the limit. - * @param buf The bytes to hash. - * @param seed The seed for the hash. - * @return The 32 bit murmur hash of the bytes in the buffer. - */ - public static int hash(ByteBuffer buf, int seed) { - // save byte order for later restoration - ByteOrder byteOrder = buf.order(); - buf.order(ByteOrder.LITTLE_ENDIAN); - - int m = 0x5bd1e995; - int r = 24; - - int h = seed ^ buf.remaining(); - - int k; - while (buf.remaining() >= 4) { - k = buf.getInt(); - - k *= m; - k ^= k >>> r; - k *= m; - - h *= m; - h ^= k; - } - - if (buf.remaining() > 0) { - ByteBuffer finish = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN); - // for big-endian version, use this first: - // finish.position(4-buf.remaining()); - finish.put(buf).rewind(); - h ^= finish.getInt(); - h *= m; - } - - h ^= h >>> 13; - h *= m; - h ^= h >>> 15; - - buf.order(byteOrder); - return h; - } - - public static long hash64A(byte[] data, int seed) { - return hash64A(ByteBuffer.wrap(data), seed); - } - - public static long hash64A(byte[] data, int offset, int length, int seed) { - return hash64A(ByteBuffer.wrap(data, offset, length), seed); - } - - public static long hash64A(ByteBuffer buf, int seed) { - ByteOrder byteOrder = buf.order(); - buf.order(ByteOrder.LITTLE_ENDIAN); - - long m = 0xc6a4a7935bd1e995L; - int r = 47; - - long h = seed ^ (buf.remaining() * m); - - long k; - while (buf.remaining() >= 8) { - k = buf.getLong(); - - k *= m; - k ^= k >>> r; - k *= m; - - h ^= k; - h *= m; - } - - if (buf.remaining() > 0) { - ByteBuffer finish = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN); - // for big-endian version, do this first: - // finish.position(8-buf.remaining()); - finish.put(buf).rewind(); - h ^= finish.getLong(); - h *= m; - } - - h ^= h >>> r; - h *= m; - h ^= h >>> r; - - buf.order(byteOrder); - return h; - } - - @Override - public long hash(byte[] key) { - return hash64A(key, 0x1234ABCD); - } - - @Override - public long hash(String key) { - return hash(SafeEncoder.encode(key)); - } -} diff --git a/src/test/java/redis/clients/jedis/benchmark/HashingBenchmark.java b/src/test/java/redis/clients/jedis/benchmark/HashingBenchmark.java deleted file mode 100644 index 1d145f0618..0000000000 --- a/src/test/java/redis/clients/jedis/benchmark/HashingBenchmark.java +++ /dev/null @@ -1,37 +0,0 @@ -package redis.clients.jedis.benchmark; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.Calendar; - -import redis.clients.jedis.util.Hashing; - -public class HashingBenchmark { - - private static final int TOTAL_OPERATIONS = 10000000; - - public static void main(String[] args) throws UnknownHostException, IOException { - - long begin = Calendar.getInstance().getTimeInMillis(); - - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - String key = "foo" + n; - Hashing.MD5.hash(key); - } - - long elapsed = Calendar.getInstance().getTimeInMillis() - begin; - - System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " MD5 ops"); - - begin = Calendar.getInstance().getTimeInMillis(); - - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - String key = "foo" + n; - Hashing.MURMUR_HASH.hash(key); - } - - elapsed = Calendar.getInstance().getTimeInMillis() - begin; - - System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " Murmur ops"); - } -}