public long hash(final String k) {
        long rv = 0;
        switch (this) {
        case NATIVE_HASH:
            rv = k.hashCode();
            break;
        case CRC32_HASH:
            // return (crc32(shift) >> 16) & 0x7fff;
            final CRC32 crc32 = new CRC32();
            crc32.update(ByteUtils.getBytes(k));
            rv = crc32.getValue() >> 16 & 0x7fff;
            break;
        case FNV1_64_HASH: {
            // Thanks to pierre@demartines.com for the pointer
            rv = FNV_64_INIT;
            final int len = k.length();
            for (int i = 0; i < len; i++) {
                rv *= FNV_64_PRIME;
                rv ^= k.charAt(i);
            }
        }
            break;
        case FNV1A_64_HASH: {
            rv = FNV_64_INIT;
            final int len = k.length();
            for (int i = 0; i < len; i++) {
                rv ^= k.charAt(i);
                rv *= FNV_64_PRIME;
            }
        }
            break;
        case FNV1_32_HASH: {
            rv = FNV_32_INIT;
            final int len = k.length();
            for (int i = 0; i < len; i++) {
                rv *= FNV_32_PRIME;
                rv ^= k.charAt(i);
            }
        }
            break;
        case FNV1A_32_HASH: {
            rv = FNV_32_INIT;
            final int len = k.length();
            for (int i = 0; i < len; i++) {
                rv ^= k.charAt(i);
                rv *= FNV_32_PRIME;
            }
        }
            break;
        case ELECTION_HASH:
        case KETAMA_HASH:
            final byte[] bKey = computeMd5(k);
            rv =
                    (long) (bKey[3] & 0xFF) << 24 | (long) (bKey[2] & 0xFF) << 16 | (long) (bKey[1] & 0xFF) << 8
                            | bKey[0] & 0xFF;
            break;

        case MYSQL_HASH:
            int nr2 = 4;
            for (int i = 0; i < k.length(); i++) {
                rv ^= ((rv & 63) + nr2) * k.charAt(i) + (rv << 8);
                nr2 += 3;
            }
            break;
        case ELF_HASH:
            long x = 0;
            for (int i = 0; i < k.length(); i++) {
                rv = (rv << 4) + k.charAt(i);
                if ((x = rv & 0xF0000000L) != 0) {
                    rv ^= x >> 24;
                    rv &= ~x;
                }
            }
            rv = rv & 0x7FFFFFFF;
            break;
        case RS_HASH:
            final long b = 378551;
            long a = 63689;
            for (int i = 0; i < k.length(); i++) {
                rv = rv * a + k.charAt(i);
                a *= b;
            }
            rv = rv & 0x7FFFFFFF;
            break;
        case LUA_HASH:
            final int step = (k.length() >> 5) + 1;
            rv = k.length();
            for (int len = k.length(); len >= step; len -= step) {
                rv = rv ^ (rv << 5) + (rv >> 2) + k.charAt(len - 1);
            }
            break;
        case ONE_AT_A_TIME:
            try {
                int hash = 0;
                for (final byte bt : k.getBytes("utf-8")) {
                    hash += bt & 0xFF;
                    hash += hash << 10;
                    hash ^= hash >>> 6;
                }
                hash += hash << 3;
                hash ^= hash >>> 11;
                hash += hash << 15;
                return hash;
            }
            catch (final UnsupportedEncodingException e) {
                throw new IllegalStateException("Hash function error", e);
            }
        default:
            assert false;
        }

        return rv & 0xffffffffL; /* Truncate to 32-bits */
    }
Compute the hash for the given key.

@return a positive integer hash
metamorphosis-client/src/main/java/com/taobao/metamorphosis/client/consumer/HashAlgorithm.java