Example usage for com.google.common.hash Hashing murmur3_32

List of usage examples for com.google.common.hash Hashing murmur3_32

Introduction

In this page you can find the example usage for com.google.common.hash Hashing murmur3_32.

Prototype

public static HashFunction murmur3_32() 

Source Link

Document

Returns a hash function implementing the <a href="http://smhasher.googlecode.com/svn/trunk/MurmurHash3.cpp"> 32-bit murmur3 algorithm, x86 variant</a> (little-endian variant), using a seed value of zero.

Usage

From source file:com.ibm.vicos.common.util.Utils.java

public static String hashMurmur3_32(String input) {
    Hasher hasher = Hashing.murmur3_32().newHasher();
    hasher.putString(input, Charsets.UTF_8);
    return hasher.hash().toString();
}

From source file:benchmarks.Benchmark32BitHash.java

@Benchmark
public int guava_murmur3_32(BenchmarkData bd, ByteCounter bc) {
    byte[] bytes = bd.getBytes();
    bc.add(bytes.length);//from  w  w w  .  j a va 2 s. com
    return Hashing.murmur3_32().hashBytes(bytes).asInt();
}

From source file:com.example.api.UrlShortener.java

String getHash(String url) {
    int hashCode = Hashing.murmur3_32().hashString(url, StandardCharsets.UTF_8).asInt();
    String hash = Integer.toHexString(hashCode);
    urlMap.putIfAbsent(hash, url);//from w ww.  j a  v a2s  .c o m
    return hash;
}

From source file:io.atomix.protocols.raft.cluster.impl.DefaultRaftMember.java

public DefaultRaftMember(MemberId id, Type type, Instant updated) {
    this.id = checkNotNull(id, "id cannot be null");
    this.hash = Hashing.murmur3_32().hashUnencodedChars(id.id()).asInt();
    this.type = checkNotNull(type, "type cannot be null");
    this.updated = checkNotNull(updated, "updated cannot be null");
}

From source file:org.apache.jackrabbit.oak.plugins.segment.standby.codec.SegmentEncoder.java

@Override
protected void encode(ChannelHandlerContext ctx, Segment s, ByteBuf out) throws Exception {
    SegmentId id = s.getSegmentId();/*w  w  w  .  j a  v a 2  s  . c  o  m*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream(s.size());
    s.writeTo(baos);
    byte[] segment = baos.toByteArray();

    Hasher hasher = Hashing.murmur3_32().newHasher();
    long hash = hasher.putBytes(segment).hash().padToLong();

    int len = segment.length + EXTRA_HEADERS_WO_SIZE;
    out.writeInt(len);
    out.writeByte(Messages.HEADER_SEGMENT);
    out.writeLong(id.getMostSignificantBits());
    out.writeLong(id.getLeastSignificantBits());
    out.writeLong(hash);
    out.writeBytes(segment);
}

From source file:io.fluo.stress.trie.Node.java

private String genHash() {
    long num = (number == null) ? 0l : number.longValue();
    int hash = Hashing.murmur3_32().newHasher().putInt(level).putInt(nodeSize).putLong(num).hash().asInt();
    hash = hash & 0x7fffffff;/*  www .ja  v a  2s  .  c o  m*/
    //base 36 gives a lot more bins in 4 bytes than hex, but it still human readable which is nice for debugging.
    String hashString = Strings.padStart(Integer.toString(hash, Character.MAX_RADIX), HASH_LEN, '0');
    return hashString.substring(hashString.length() - HASH_LEN);
}

From source file:io.viewserver.core.ConsistentHash.java

public ConsistentHash(int numberOfReplicas, Collection<Integer> nodes) {
    this(Hashing.murmur3_32(), numberOfReplicas, nodes);
}

From source file:org.apache.accumulo.core.client.summary.SummarizerConfiguration.java

private SummarizerConfiguration(String className, String configId, Map<String, String> options) {
    this.className = className;
    this.options = ImmutableMap.copyOf(options);

    if (configId == null) {
        ArrayList<String> keys = new ArrayList<>(this.options.keySet());
        Collections.sort(keys);//from   w  w w  . ja v  a2  s.c  o  m
        Hasher hasher = Hashing.murmur3_32().newHasher();
        hasher.putString(className, UTF_8);
        for (String key : keys) {
            hasher.putString(key, UTF_8);
            hasher.putString(options.get(key), UTF_8);
        }

        this.configId = hasher.hash().toString();
    } else {
        this.configId = configId;
    }
}

From source file:lbaas.util.HashAlgorithm.java

public int hash(Object key) {
    HashCode hashCode;//from   ww w  .ja v a2  s . c  o  m
    HashFunction hashAlgorithm;
    switch (hashType) {
    case MD5:
        hashAlgorithm = Hashing.md5();
        break;
    case MURMUR3_32:
        hashAlgorithm = Hashing.murmur3_32();
        break;
    case SHA256:
        hashAlgorithm = Hashing.sha256();
        break;
    case SIP24:
        hashAlgorithm = Hashing.sipHash24();
        break;
    default:
        hashAlgorithm = Hashing.sipHash24();
        break;
    }
    if (key instanceof String) {
        hashCode = hashAlgorithm.newHasher().putString((String) key, Charsets.UTF_8).hash();
    } else if (key instanceof Long) {
        hashCode = hashAlgorithm.newHasher().putLong((Long) key).hash();
    } else {
        hashCode = hashAlgorithm.newHasher().hash();
    }
    return hashCode.asInt();
}

From source file:com.jeffplaisance.util.fingertree.bytestring.ByteString.java

@Override
public int hashCode() {
    try {/*from   w  w w.ja  va2 s.  co m*/
        return ByteStreams.hash(new InputSupplier<InputStream>() {
            @Override
            public InputStream getInput() throws IOException {
                return newInput();
            }
        }, Hashing.murmur3_32()).asInt();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}