Guest User

Untitled

a guest
Apr 1st, 2016
148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data