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

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

Introduction

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

Prototype

@Override
    Hasher putInt(int i);

Source Link

Usage

From source file:mx.itam.metodos.minhashing.MinhashMapper.java

@Override
public void map(Text id, IntArrayWritable values, Context ctx) throws IOException, InterruptedException {
    for (int i = 0; i < functionsCount; i++) {
        hashValues[i] = Integer.MAX_VALUE;
    }// w w  w. j a  v a  2s. co  m
    for (int i = 0; i < functionsCount; i++) {
        HashFunction hf = functions[i];
        for (Writable wr : values.get()) {
            IntWritable value = (IntWritable) wr;
            int hash = hf.hashInt(value.get()).asInt();
            if (hash < hashValues[i]) {
                hashValues[i] = hash;
            }
        }
    }
    Text sketch = new Text();
    Hasher hasher = lsh.newHasher();
    int band = 0;
    for (int i = 0; i < functionsCount; i++) {
        hasher.putInt(hashValues[i]);
        if (i > 0 && (i % rows) == 0) {
            sketch.set(band + "-" + hasher.hash().toString());
            write(id, sketch, ctx);
            hasher = lsh.newHasher();
            band++;
        }
    }
    sketch.set(band + "-" + hasher.hash().toString());
    write(id, sketch, ctx);
}

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

@Override
public Hasher putInt(int i) {
    for (Hasher hasher : hashers) {
        hasher.putInt(i);
    }/*from www . j  a v  a  2s. c  om*/
    return this;
}

From source file:com.spotify.heroic.metric.ShardedResultGroup.java

public int hashGroup() {
    final Hasher hasher = HASH_FUNCTION.newHasher();

    for (Map.Entry<String, String> e : shard.entrySet()) {
        hasher.putInt(RECORD_SEPARATOR);
        hasher.putString(e.getKey(), Charsets.UTF_8);
        hasher.putInt(RECORD_SEPARATOR);
        hasher.putString(e.getValue(), Charsets.UTF_8);
    }/*ww  w . ja v  a2s  . c  om*/

    hasher.putInt(RECORD_SEPARATOR);

    for (Map.Entry<String, String> e : key.entrySet()) {
        hasher.putInt(RECORD_SEPARATOR);
        hasher.putString(e.getKey(), Charsets.UTF_8);
        hasher.putInt(RECORD_SEPARATOR);
        hasher.putString(e.getValue(), Charsets.UTF_8);
    }

    return hasher.hash().asInt();
}

From source file:com.mapr.synth.NestedRandom.java

private void hash(Hasher hasher) {
    if (content != null) {
        hasher.putString(content, Charsets.UTF_8);
    } else {//  w w w .  j a  va 2  s.  co  m
        hasher.putInt(seed);
    }
    if (parent != null) {
        parent.hash(hasher);
    }
}

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. //  w  w w .ja v  a2  s.  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.jeffplaisance.util.fingertree.list.IndexedList.java

@Override
public int hashCode() {
    final Hasher hasher = Hashing.murmur3_32().newHasher();
    for (T t : this) {
        hasher.putInt(t.hashCode());
    }/*from   w  ww  .  j  a v a  2s. c  om*/
    return hasher.hash().asInt();
}

From source file:com.facebook.buck.rules.macros.AbstractStringWithMacrosConverter.java

/**
 * Expand the input given for the this macro to some string, which is intended to be written to a
 * file./*from w  w w.j  a va  2  s  .c  o m*/
 */
private Arg expand(MacroContainer macroContainer, ActionGraphBuilder ruleResolver) throws MacroException {
    Arg arg = expand(macroContainer.getMacro(), ruleResolver);

    // If specified, wrap this macro's output in a `WriteToFileArg`.
    if (macroContainer.isOutputToFile()) {
        // "prefix" should give a stable name, so that the same delegate with the same input can
        // output the same file. We won't optimise for this case, since it's actually unlikely to
        // happen within a single run, but using a random name would cause 'buck-out' to expand in an
        // uncontrolled manner.
        Hasher hasher = Hashing.sha256().newHasher();
        hasher.putString(macroContainer.getMacro().getClass().getName(), UTF_8);
        hasher.putInt(macroContainer.getMacro().hashCode());
        String prefix = hasher.hash().toString();
        arg = new WriteToFileArg(getBuildTarget(), prefix, arg);
    }

    return arg;
}

From source file:com.google.gitiles.doc.DocServlet.java

private String etag(SourceFile srcmd, SourceFile navmd) {
    byte[] b = new byte[Constants.OBJECT_ID_LENGTH];
    Hasher h = Hashing.sha1().newHasher();
    h.putInt(ETAG_GEN);

    renderer.getTemplateHash(SOY_FILE).writeBytesTo(b, 0, b.length);
    h.putBytes(b);//from   www  . j av a 2  s  .com

    if (navmd != null) {
        navmd.id.copyRawTo(b, 0);
        h.putBytes(b);
    }

    srcmd.id.copyRawTo(b, 0);
    h.putBytes(b);
    return h.hash().toString();
}

From source file:org.apache.marmotta.commons.sesame.tripletable.IntArray.java

private void ensureHashCode() {
    if (hashCode32 == null) {
        Hasher hasher = hashFunction32.newHasher();
        for (int i : data) {
            hasher.putInt(i);
        }/* w  w  w .  j av  a  2 s  .  c o  m*/
        hashCode32 = hasher.hash();
    }
}

From source file:org.apache.marmotta.commons.sesame.tripletable.IntArray.java

private void ensureLongHashCode() {
    if (hashCode64 == null) {
        Hasher hasher = hashFunction64.newHasher();
        for (int i : data) {
            hasher.putInt(i);
        }/*www  . ja v  a  2 s.  c  o  m*/
        hashCode64 = hasher.hash();
    }

}