Advertisement
Guest User

Untitled

a guest
Apr 1st, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. int numCollisions = 0;
  2. Set<Integer> hashes = new HashSet<>();
  3. Set<Integer> collisions = new HashSet<>();
  4. for (String word : words) {
  5. int hash = hashFunc.apply(word);
  6. if (hash < 0 || hash >= 16777216) {
  7. throw new Exception("hash too long for word: " + word + " hash: " + hash);
  8. }
  9.  
  10. if(!hashes.add(hash)) {
  11. numCollisions++;
  12. if (collisions.add(hash)) {
  13. numCollisions++;
  14. }
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement