Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int numCollisions = 0;
- Set<Integer> hashes = new HashSet<>();
- Set<Integer> collisions = new HashSet<>();
- for (String word : words) {
- int hash = hashFunc.apply(word);
- if (hash < 0 || hash >= 16777216) {
- throw new Exception("hash too long for word: " + word + " hash: " + hash);
- }
- if(!hashes.add(hash)) {
- numCollisions++;
- if (collisions.add(hash)) {
- numCollisions++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement