2017-10-24 9 views
0

私はJavaプロジェクトで(universal) family of pairwise independent hash functionsを使用する簡単かつ簡単な方法をお探しです。Javaのペア独立ハッシュ関数

理想的には、整数をハッシュするメソッドhash()でオブジェクトを返すオブジェクトUniversalFamily(ファミリーを表す)があります。

使用例:

// use this object to generate pairwise independent hash functions 
UniversalFamily family = new UniversalFamily(); 

// these objects represent the pairwise independent hash functions 
HashF hashF1 = fam.getHashFunction(); 
HashF hashF2 = fam.getHashFunction(); 
// ... 

/* here the hash functions are being used to hash the integers 1, 2 and 
    1337, the return values (not stored) are the results of the 
    corresponding hash functions. */ 
hashF1.hash(1); 
hashF1.hash(2); 
hashF2.hash(1337); 
// ... 

私の周りいじり始める前に、すでに利用可能なこのようなものがありますか?

+0

'hashF2.hash;' '1337'この例では何ですか? –

+0

@ JigarJoshi整数です。私は整数をハッシュすることに興味があります。 –

+0

私はこれが広すぎて話題にならないかもしれないと恐れています、あなたはちょっとお勧めです。とにかく、私はヘルプセクションに適切な行を見つけることができず、個人的にあなたの質問の明瞭さ(あなたが編集していると思う仕事の量)が好きなので、私はそれを報告しません。がんばろう。 –

答えて

0
このような

使用何か:(1337)

/* Used to generate and encapsulate pairwise independent hash functions. 
See see https://people.csail.mit.edu/ronitt/COURSE/S12/handouts/lec5.pdf , claim 5 for more information. 
*/ 
private static class HashF { 

    private final int a; 
    private final int b; 
    private final int p = 1610612741; // prime 

    HashF(int a, int b) { 
     Random rand = new Random(); 

     this.a = rand.nextInt(p); 
     this.b = rand.nextInt(p); 
    } 

    // hashes integers 
    public int hash(int x) { 
     return (a*x + b) % p; 
    } 

} 
関連する問題