Coder Social home page Coder Social logo

Comments (4)

alexgarbarev avatar alexgarbarev commented on August 19, 2024

Wow! Nice catch.
Of course, any PR is very welcome!

from typhoon.

alexgarbarev avatar alexgarbarev commented on August 19, 2024

Hey @daria-kopaliani,
I reviewed the code again, I can't understand why this shift is invalid?

This is "31 multiply" hash function well known in Java world,
https://docs.oracle.com/javase/6/docs/api/java/lang/String.html#hashCode()

So the hash function is
hash = 31 * hash + value or hash = hash << 5 - hash + value
See more details in this answer:
https://stackoverflow.com/a/299748/1817391

I suggest to do 31 multiplication if shift is not working anymore.


Meanwhile XOR is not good for hash, because A ^ B == B ^ A

from typhoon.

alexgarbarev avatar alexgarbarev commented on August 19, 2024

Hello @daria-kopaliani, sorry for long delay. I'm going to fix this issue.
Can you remember how this issue happened? Was it 32bit device? I'm unable to replicate it.

from typhoon.

alexgarbarev avatar alexgarbarev commented on August 19, 2024

Well.. I found the reason of that problem. There is a typo 5 << hash instead of hash << 5 🤦, so instead of shifting hash by 5 bits to right, I shifted 5 by hash bits to right. It looks like your compile flags were set to stop when shifting happens by more than 32 bits at once (as I know it's unexpected behaviour)..

from typhoon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.