Reputation: 187
Okay guys, I am working hashmap, using one of my classes as Key.
My question is: When I get the correct item one time, is it possible to get a bad item on another time?
I mean, I implemented a hashcode algorithm that I view here on another question. And sometimes I get the correct item, another times I dont get it.
Any guess ? is it possible to find one time and right the second time cant find it ? I am not deleting it !
Thanks alot in advance !
Upvotes: 0
Views: 112
Reputation: 133557
Of course not, you need consistency. A hash value must always be the same for the same item if calculated with the same algorithm.
A possible answer to your problem is that you are calculating using some internal value of your object that is modified between first search and second search.
You can possibly get collisions in the sense that two values are mapped to the same hash value but you can't have something that the first time works while the second time it doesn't.
Upvotes: 3