Package com.google.common.hash

Examples of com.google.common.hash.HashFunction


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


  @Test
  public void testObama() throws IOException {
    SketchSet ss = new SketchSet();
    SketchSet ss2 = new SketchSet();
   
    HashFunction md5 = Hashing.md5();
   
    System.out.println(" Directory is " + System.getProperty("user.dir"));
    FileInputStream fs = new FileInputStream("src/test/resources/obama.txt");
    int cnt =0;
    BufferedReader reader = new BufferedReader( new InputStreamReader(fs ));
    String line;
    while( (line = reader.readLine() ) != null) {
      ss.addItem( line);
      ss2.addHashItemmd5.hashUnencodedChars( line).asLong(), line );
      cnt++;
    }
   
    System.out.println(" Estimated Reach = " + ss.estimateReach() + " count = " + cnt);
    double diff = cnt - ss.estimateReach();
View Full Code Here

  }

  @Test(groups = "fast")
  public void testPumaAndGuavaLongMurmurHash() throws Exception {
    // our impl is slightly faster, and this is just a check to see we match guava
    HashFunction function = Hashing.murmur3_128((int) MurmurHash.JCOMMON_SEED);
    int numToCheck = 10000;

    for (int i = 0; i < numToCheck; i++) {
      long input = random.nextLong();

      Assert.assertEquals(repeatableHasher.hash(input), function.hashLong(input).asLong());
    }

  }
View Full Code Here

        this.userId = userId;
        this.createdAtMs = createdAtMs;
    }

    public String getContentId(){
        HashFunction md5 = Hashing.md5();
        return md5.hashString(contentType + contentName).toString();
    }
View Full Code Here

    Closure<LogEntry> reader = createMock(new Clazz<Closure<LogEntry>>() { });
    reader.execute(snapshotLogEntry);

    control.replay();

    HashFunction md5 = Hashing.md5();
    StreamManagerImpl streamManager = new StreamManagerImpl(
        stream,
        new EntrySerializer.EntrySerializerImpl(NO_FRAMES_EVER_SIZE, md5),
        true,
        md5,
View Full Code Here

    snapshotDeduplicator = createMock(SnapshotDeduplicator.class);

    StreamManagerFactory streamManagerFactory = new StreamManagerFactory() {
      @Override
      public StreamManager create(Stream logStream) {
        HashFunction md5 = Hashing.md5();
        return new StreamManagerImpl(
            logStream,
            new EntrySerializer.EntrySerializerImpl(
                Amount.of(1, Data.GB),
                md5),
View Full Code Here

public class Murmur3HashFunctionTests extends ElasticsearchTestCase {

    public void test() {
        // Make sure that we agree with guava
        Murmur3HashFunction murmur3 = new Murmur3HashFunction();
        HashFunction guavaMurmur3 = Hashing.murmur3_32();
        for (int i = 0; i < 100; ++i) {
            final String id = RandomStrings.randomRealisticUnicodeOfCodepointLength(getRandom(), RandomInts.randomIntBetween(getRandom(), 1, 20));
            //final String id = "0";
            final int hash1 = guavaMurmur3.newHasher().putUnencodedChars(id).hash().asInt();
            final int hash2 = murmur3.hash(id);
            assertEquals(hash1, hash2);
        }
    }
View Full Code Here

        {
            final Person customer = (Person) request.getSession().getAttribute("customer");
            PasswordGenerator generator = Generator.newPasswordGenerator(8, true, true, true, true);
            try {
                final String password = generator.generate();
                HashFunction hf = Hashing.sha1();
                HashCode hc = hf.newHasher()
                    .putString(password)
                    .hash();
                customer.setPassword(hc.toString());
                customer.addAccount(account);
                customerService.processCustomer(customer, password);
View Full Code Here

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        final String email = request.getParameter("mail");
        final String password = request.getParameter("password");
       
        HashFunction hf = Hashing.sha1();
        HashCode hc = hf.newHasher()
                .putString(password)
                .hash();
       
        final String hashedPassword = hc.toString();
      
View Full Code Here

TOP

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

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.