Guest User

Untitled

a guest
Feb 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. int hashCode() {
  2. int result = 0;
  3. for (int i=0; i<bits.length; ++i) {
  4. long word = bits[i];
  5. result += 64 * i * Long.bitCount(word) + weightedBitCount(word);
  6. }
  7. return result;
  8. }
  9.  
  10. int weightedBitCount(long word) { // naive implementation
  11. int result = 0;
  12. for (int i=0; i<64; ++i) {
  13. if ((word & (1L << i)) != 0) {
  14. result += i;
  15. }
  16. }
  17. return result;
  18. }
Add Comment
Please, Sign In to add comment