Package com.google.common.hash

Examples of com.google.common.hash.HashCode


   * @param element The byte array that may have been previously seen.
   * @return Whether the element is contained in the OoaBFilter.
   */
  public boolean containsAndAdd(Element element) {
    ByteBuffer eBytes = element.getByteBuffer();
    HashCode code = HASH_FUNC.hashBytes(eBytes.array());
    int index = code.asInt() & sizeMask;

    boolean seen = true;
    ByteBuffer buffer = array[index];

    synchronized(buffer) {
View Full Code Here


     * @param args
     */
    public static void main(String[] args) {
        // Common Hash
        HashFunction hf = Hashing.goodFastHash(32);
        HashCode code = hf.hashObject(new Person(1, "Jiyun", "Xie", 1984), PersonFunnel.INSTANCE);
        System.out.println("Code1 => " + code.asInt());
        code = hf.hashObject(new Person(1, "Jiyun", "Xie", 1985), PersonFunnel.INSTANCE);
        System.out.println("Code2 => " + code.asInt());
        // Consistent Hashing
        HashFunction hf2 = Hashing.goodFastHash(64);
        code = hf2.hashObject(new Person(1, "Jiyun", "Xie", 1984), PersonFunnel.INSTANCE);
        System.out.println("Code3 => " + code.asLong());
        long hash = code.asLong();
        int bucket = Hashing.consistentHash(code, 100);
        System.out.println("Bucket1 => " + bucket);
        bucket = Hashing.consistentHash(hash, 101);
        System.out.println("Bucket2 => " + bucket);
        for (int i = 0; i < 10; ++i) {
View Full Code Here

                        @Override
                        public long getValue() {
                            throw new UnsupportedOperationException();
                        }
                    }));
            HashCode hash = hasher.hash();

            // wrap into AbstractBlob for the SHA-256 memorization feature
            if (!(blob instanceof AbstractBlob)) {
                final Blob b = blob;
                blob = new AbstractBlob(hash) {
                    @Override
                    public long length() {
                        return b.length();
                    }
                    @Override
                    public InputStream getNewStream() {
                        return b.getNewStream();
                    }
                };
            }

            String id = hash.toString();
            blobs.put(id, blob);
            return id;
        } catch (IOException e) {
            throw new MicroKernelException("Failed to create a blob", e);
        }
View Full Code Here

        return ((Regressor) model).regress(features);
    }

    private static Model getOrLoadModel(Slice slice)
    {
        HashCode modelHash = ModelUtils.modelHash(slice);

        Model model = MODEL_CACHE.getIfPresent(modelHash);
        if (model == null) {
            model = ModelUtils.deserialize(slice);
            MODEL_CACHE.put(modelHash, model);
View Full Code Here

    {
        int version = slice.getInt(VERSION_OFFSET);
        checkArgument(version == CURRENT_FORMAT_VERSION, format("Unsupported version: %d", version));

        byte[] modelHashBytes = slice.getBytes(HASH_OFFSET, 32);
        HashCode expectedHash = HashCode.fromBytes(modelHashBytes);
        HashCode actualHash = Hashing.sha256().hashBytes(slice.getBytes(ALGORITHM_OFFSET, slice.length() - ALGORITHM_OFFSET));
        checkArgument(actualHash.equals(expectedHash), "model hash does not match data");

        int id = slice.getInt(ALGORITHM_OFFSET);
        Class<? extends Model> algorithm = MODEL_SERIALIZATION_IDS.inverse().get(id);
        checkNotNull(algorithm, "Unsupported algorith %d", id);
View Full Code Here

   *
   * @param data data to hash
   * @return 128 bits of hash result
   */
  public byte[] hash(byte[] data) {
    HashCode hashCode = byteArrayHasher.hashBytes(data);

    return hashCode.asBytes();
  }
View Full Code Here

    return hashCode.asBytes();
  }

  public long hashToLong(byte[] data) {
    HashCode hashCode = byteArrayHasher.hashBytes(data);

    return hashCode.asLong();
  }
View Full Code Here

        _entriesPerEndPoint = entriesPerEndPoint;
    }

    @Override
    public Iterable<ServiceEndPoint> filter(Iterable<ServiceEndPoint> endPoints, PartitionContext partitionContext) {
        HashCode partitionHash = getPartitionHash(partitionContext);
        if (partitionHash == null) {
            return endPoints;  // No partition hash means any server can handle the request.
        }

        // The choose() method is synchronized.  Do any prep work we can up front before calling into it.
View Full Code Here

     * @return the hash or null if an error happened
     */
    @Nullable
    private static String getFileHash(@NonNull File file) {
        try {
            HashCode hashCode = Files.hash(file, Hashing.sha1());
            return hashCode.toString();
        } catch (IOException ignored) {

        }

        return null;
View Full Code Here

     * @return the hash or null if an error happened
     */
    @Nullable
    private static String getFileHash(@NonNull File file) {
        try {
            HashCode hashCode = Files.hash(file, Hashing.sha1());
            return hashCode.toString();
        } catch (IOException ignored) {

        }

        return null;
View Full Code Here

TOP

Related Classes of com.google.common.hash.HashCode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.