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

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

Introduction

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

Prototype

public static HashFunction goodFastHash(int minimumBits) 

Source Link

Document

Returns a general-purpose, temporary-use, non-cryptographic hash function.

Usage

From source file:com.android.tools.idea.gradle.run.GradleInstantRunContext.java

@VisibleForTesting
static HashCode getManifestResourcesHash(@NotNull AndroidFacet facet) {
    Document manifest = MergedManifest.get(facet).getDocument();
    if (manifest == null || manifest.getDocumentElement() == null) {
        return HashCode.fromInt(0);
    }/*from ww  w.  j a va  2s  . com*/

    final Hasher hasher = Hashing.goodFastHash(32).newHasher();
    SortedSet<ResourceUrl> appResourceReferences = getAppResourceReferences(manifest.getDocumentElement());
    AppResourceRepository appResources = AppResourceRepository.getAppResources(facet, true);

    // read action needed when reading the values for app resources
    ApplicationManager.getApplication().runReadAction(() -> {
        hashResources(appResourceReferences, appResources, hasher);
    });

    return hasher.hash();
}

From source file:com.steeleforge.aem.ironsites.wcm.WCMUtil.java

/**
 * General purpose hashing for Strings such as node path.
 * /*from  w w w. ja v a  2  s. c o  m*/
 * @param token String to hash
 * @param minimumLength minimum length of hash
 * @return hashed value
 * @see <a href="http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/hash/HashCode.html">HashCode</a>
 */
public static String getFastHash(String token, int minimumLength) {
    HashFunction hf = Hashing.goodFastHash(minimumLength);
    HashCode hc = hf.newHasher().putString(token, Charsets.UTF_8).hash();
    return hc.toString();
}

From source file:org.apache.marmotta.commons.sesame.model.LiteralCommons.java

/**
 * Create a cache key for a literal with the given content, locale and type
 *
 * @param content  string content representing the literal (can be an MD5 sum for binary types)
 * @param language language of the literal (optional)
 * @param type     datatype URI of the literal (optional)
 * @return a 64bit hash key for the literal
 *///  w  w w . j  ava 2 s .  c  o  m
public static String createCacheKey(String content, String language, String type) {
    Hasher hasher = Hashing.goodFastHash(HASH_BITS).newHasher();
    hasher.putString(content, Charset.defaultCharset());
    if (type != null) {
        hasher.putString(type, Charset.defaultCharset());
    }
    if (language != null) {
        hasher.putString(language.toLowerCase(), Charset.defaultCharset());
    }
    return hasher.hash().toString();
}

From source file:org.apache.marmotta.commons.http.ETagGenerator.java

private static Hasher buildHasher() {
    HashFunction function = Hashing.goodFastHash(16);
    Hasher hasher = function.newHasher();
    return hasher;
}

From source file:com.torodb.kvdocument.values.KvDocument.java

@Override
public int hashCode() {
    return Hashing.goodFastHash(32).hashInt(size()).asInt();
}

From source file:hyperloglog.HyperLogLog.java

private HyperLogLog(HyperLogLogBuilder hllBuilder) {
    if (hllBuilder.numRegisterIndexBits < HLLConstants.MIN_P_VALUE
            || hllBuilder.numRegisterIndexBits > HLLConstants.MAX_P_VALUE) {
        throw new IllegalArgumentException(
                "p value should be between " + HLLConstants.MIN_P_VALUE + " to " + HLLConstants.MAX_P_VALUE);
    }/*from ww w  .  j a v a 2 s  .  c o  m*/
    this.p = hllBuilder.numRegisterIndexBits;
    this.m = 1 << p;
    this.noBias = hllBuilder.noBias;
    this.bitPacking = hllBuilder.bitPacking;

    // the threshold should be less than 12K bytes for p = 14.
    // The reason to divide by 5 is, in sparse mode after serialization the
    // entriesin sparse map are compressed, and delta encoded as varints. The
    // worst case size of varints are 5 bytes. Hence, 12K/5 ~= 2400 entries in
    // sparse map.
    if (bitPacking) {
        this.encodingSwitchThreshold = ((m * 6) / 8) / 5;
    } else {
        // if bitpacking is disabled, all register values takes 8 bits and hence
        // we can be more flexible with the threshold. For p=14, 16K/5 = 3200
        // entries in sparse map can be allowed.
        this.encodingSwitchThreshold = m / 3;
    }

    // we won't need hash functions beyond 128 bits.. in fact 64 bits itself is
    // more than sufficient
    if (hllBuilder.numHashBits > 128) {
        this.hf = Hashing.goodFastHash(128);
    } else {
        this.hf = Hashing.goodFastHash(hllBuilder.numHashBits);
    }
    this.chosenHashBits = hf.bits();
    initializeAlpha();
    this.cachedCount = -1;
    this.invalidateCount = false;
    this.encoding = hllBuilder.encoding;
    if (encoding.equals(EncodingType.SPARSE)) {
        this.sparseRegister = new HLLSparseRegister(p, HLLConstants.P_PRIME_VALUE, HLLConstants.Q_PRIME_VALUE);
        this.denseRegister = null;
    } else {
        this.sparseRegister = null;
        this.denseRegister = new HLLDenseRegister(p, bitPacking);
    }
}

From source file:com.turn.splicer.merge.ResultsMerger.java

public long signatureOf(TsdbResult result) {
    HashFunction hf = Hashing.goodFastHash(64);
    Hasher hasher = hf.newHasher();/*w  ww .  j av a 2  s. c  om*/

    List<String> aggTags = result.getAggregateTags();
    if (aggTags != null) {
        List<String> sortedAggTags = Lists.newArrayList(aggTags);
        Collections.sort(sortedAggTags);
        for (String aggTag : sortedAggTags) {
            hasher.putString(aggTag, Charset.forName("ISO-8859-1"));
        }
    }

    Map<String, String> tags;
    if (result.getTags() != null && (tags = result.getTags().getTags()) != null) {
        List<String> tagTokens = Lists.newArrayList(tags.keySet());
        Collections.sort(tagTokens);
        for (String s : tagTokens) {
            hasher.putString(s, Charset.forName("ISO-8859-1"));
            hasher.putString(tags.get(s), Charset.forName("ISO-8859-1"));
        }
    }

    List<String> tsuids = result.getTsuids();
    if (tsuids != null) {
        List<String> sortedTsUIDs = Lists.newArrayList(tsuids);
        Collections.sort(sortedTsUIDs);
        for (String tsuid : sortedTsUIDs) {
            hasher.putString(tsuid, Charset.forName("ISO-8859-1"));
        }
    }

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

From source file:com.android.tools.idea.rendering.TagSnapshot.java

/** Creates a signature/fingerprint of this tag snapshot (which encapsulates the tag name and attributes */
public long getSignature() {
    HashFunction hashFunction = Hashing.goodFastHash(64);
    Hasher hasher = hashFunction.newHasher();
    hasher.putString(tagName, UTF_8);/*from   w ww.  j a  va 2 s .  co  m*/
    for (AttributeSnapshot attribute : attributes) {
        if (attribute.prefix != null) {
            hasher.putString(attribute.prefix, UTF_8);
        }
        hasher.putString(attribute.name, UTF_8);
        if (attribute.value != null) {
            hasher.putString(attribute.value, UTF_8);
        }
        // Note that we're not bothering with namespaces here; the prefix will identify it uniquely
    }
    return hasher.hash().asLong();
}

From source file:org.openmicroscopy.shoola.keywords.ThumbnailCheckLibrary.java

/**
 * <table>/*from  w  w w.j  a  v a2  s.  com*/
 *   <td>Get Thumbnail Hash</td>
 *   <td>name of image whose thumbnail is queried</td>
 * </table>
 * @param imageFilename the name of the image
 * @return the hash of the thumbnail canvas image
 * @throws MultipleComponentsFoundException if multiple thumbnails exist for the given name
 * @throws ComponentNotFoundException if no thumbnails exist for the given name
 */
public String getThumbnailHash(String imageFilename)
        throws ComponentNotFoundException, MultipleComponentsFoundException {
    final RenderedImage image = captureImage("thumbnail", imageFilename);
    final IteratorIntPixel pixels = new IteratorIntPixel(image);
    final Hasher hasher = Hashing.goodFastHash(128).newHasher();
    while (pixels.hasNext()) {
        hasher.putInt(pixels.next());
    }
    return hasher.hash().toString();
}

From source file:zotmc.collect.recipe.BasicRecipeView.java

@Override
public int hashCode() {
    Hasher h = Hashing.goodFastHash(32).newHasher().putInt(asInfo(getOutput()).hashCode());

    Category cat = getCategory();/* www  .j a  va 2s.  com*/

    if (cat == SHAPED) {
        h.putBoolean(false).putBoolean(true);

        Matrix<RecipeElement> input = getShapedInput();
        if (isMirrored())
            h.putInt(input.hashCode() ^ horizontalMirror(input).hashCode());
        else
            h.putInt(input.hashCode());
    }

    else if (cat == SHAPELESS)
        h.putBoolean(true).putBoolean(false).putInt(getShapelessInput().hashCode());

    else
        h.putBoolean(false).putBoolean(false);

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