Example usage for com.google.common.hash Hasher putObject

List of usage examples for com.google.common.hash Hasher putObject

Introduction

In this page you can find the example usage for com.google.common.hash Hasher putObject.

Prototype

<T> Hasher putObject(T instance, Funnel<? super T> funnel);

Source Link

Document

A simple convenience for funnel.funnel(object, this) .

Usage

From source file:io.github.maxymania.powercache.hash.Util.java

public static byte[] hash(HashFunction hf, Object obj) {
    Hasher digest = hf.newHasher();
    digest.putObject(obj, funnel);
    return digest.hash().asBytes();
}

From source file:io.github.maxymania.powercache.hash.Util.java

public static byte[] hash(HashFunction hf, String catname, Object[] obj) {
    Hasher digest = hf.newHasher();
    digest.putString(catname, UTF);/*  w w w  .j  a va 2 s  .co m*/
    digest.putObject(obj, funnel);
    return digest.hash().asBytes();
}

From source file:io.github.maxymania.powercache.proxy.MethodCall.java

@Override
public int hashCode() {
    //int hash = 7;
    //hash = 79 * hash + Objects.hashCode(this.name);
    //hash = 79 * hash + Arrays.deepHashCode(this.data);
    //return hash;
    Hasher h = Hashing.adler32().newHasher();
    h.putString(name, Util.UTF);/*from  w  ww  . j  a v  a 2s.c o m*/
    h.putObject(data, Util.funnel);
    return h.hash().asInt();
}

From source file:com.eucalyptus.network.NetworkInfoBroadcaster.java

private static int fingerprint(final NetworkInfoSource source,
        final List<com.eucalyptus.cluster.Cluster> clusters, final Set<String> dirtyPublicAddresses,
        final String networkConfiguration) {
    final HashFunction hashFunction = goodFastHash(32);
    final Hasher hasher = hashFunction.newHasher();
    final Funnel<VersionedNetworkView> versionedItemFunnel = new Funnel<VersionedNetworkView>() {
        @Override/*w  w  w. j a  v  a 2  s .  com*/
        public void funnel(final VersionedNetworkView o, final PrimitiveSink primitiveSink) {
            primitiveSink.putString(o.getId());
            primitiveSink.putChar('=');
            primitiveSink.putInt(o.getVersion());
        }
    };
    for (final Map.Entry<String, Iterable<? extends VersionedNetworkView>> entry : source.getView()
            .entrySet()) {
        hasher.putString(entry.getKey());
        for (final VersionedNetworkView item : entry.getValue()) {
            hasher.putObject(item, versionedItemFunnel);
        }
    }
    hasher.putString(Joiner.on(',').join(Sets.newTreeSet(Iterables.transform(clusters, HasName.GET_NAME))));
    hasher.putString(Joiner.on(',').join(Sets.newTreeSet(dirtyPublicAddresses)));
    hasher.putInt(networkConfiguration.hashCode());
    return hasher.hash().asInt();
}

From source file:com.github.mgunlogson.cuckoofilter4j.SerializableSaltedHasher.java

HashCode hashObj(T object) {
    Hasher hashInst = hasher.newHasher();
    hashInst.putObject(object, funnel);
    hashInst.putLong(seedNSalt);
    return hashInst.hash();
}

From source file:com.github.mgunlogson.cuckoofilter4j.SerializableSaltedHasher.java

/**
 * hashes the object with an additional salt. For purpose of the cuckoo
 * filter, this is used when the hash generated for an item is all zeros.
 * All zeros is the same as an empty bucket, so obviously it's not a valid
 * tag. //from   www .  j  av a  2s.  c  o m
 */
HashCode hashObjWithSalt(T object, int moreSalt) {
    Hasher hashInst = hasher.newHasher();
    hashInst.putObject(object, funnel);
    hashInst.putLong(seedNSalt);
    hashInst.putInt(moreSalt);
    return hashInst.hash();
}

From source file:com.facebook.buck.util.hash.AppendingHasher.java

@Override
public <T> Hasher putObject(T instance, Funnel<? super T> funnel) {
    for (Hasher hasher : hashers) {
        hasher.putObject(instance, funnel);
    }//w w w .j  a  va 2s . com
    return this;
}