Package com.google.common.hash

Examples of com.google.common.hash.HashCode.asInt()


     * Default constructor.
     */
    ExceptionKey() {
        final HashFunction hashFunction = Hashing.md5();
        final HashCode hashCode = hashFunction.newHasher().putString(UUID.randomUUID().toString()).hash();
        this.key = hashCode.asInt();
        this.machineName = "UNKNOWN";
        try {
            InetAddress localMachine = java.net.InetAddress.getLocalHost();
            if (localMachine != null) {
                this.machineName = localMachine.getHostName();
View Full Code Here


   * @param id The byte array that may have been previously seen.
   * @return Whether the byte array is contained in the ByteArrayFilter.
   */
  public boolean containsAndAdd(byte[] id) {
    HashCode code = HASH_FUNC.hashBytes(id);
    int index = Math.abs(code.asInt()) & sizeMask;
    byte[] oldId = array.getAndSet(index, id);
    return Arrays.equals(id, oldId);
  }

  /**
 
View Full Code Here

   * @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

     */
    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);
View Full Code Here

        // 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();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.