Linked Questions
68 questions linked to/from Best implementation for hashCode method for a collection
-2
votes
2
answers
1k
views
implementing the hashcode of a pojo in an efficient manner in java [duplicate]
In an interview it was asked from me to show the implementation of hashcode and equals method in an efficient manner so i have constructed the below pojo but the interviewer said that this is not the ...
0
votes
0
answers
70
views
Deciding the right HashCode [duplicate]
I have a class Car:
public class Car{
final int uniqueId;
Car(int id)
{
uniqueId=id;
}
}
I have to store this as key in a HashMap. The max cars will be 1000. I have ...
1692
votes
25
answers
308k
views
What is the best algorithm for overriding GetHashCode?
In .NET, the GetHashCode method is used in a lot of places throughout the .NET base class libraries. Implementing it properly is especially important to find items quickly in a collection or when ...
382
votes
12
answers
668k
views
Key existence check in HashMap
Is checking for key existence in HashMap always necessary?
I have a HashMap with say a 1000 entries and I am looking at improving the efficiency.
If the HashMap is being accessed very frequently, ...
122
votes
3
answers
33k
views
Magic number in boost::hash_combine
The boost::hash_combine template function takes a reference to a hash (called seed) and an object v. According to the docs, it combines seed with the hash of v by
seed ^= hash_value(v) + 0x9e3779b9 + (...
100
votes
6
answers
109k
views
Most efficient property to hash for numpy array
I need to be able to store a numpy array in a dict for caching purposes. Hash speed is important.
The array represents indicies, so while the actual identity of the object is not important, the ...
59
votes
5
answers
38k
views
HashMap implementation in Java. How does the bucket index calculation work?
I am looking at the implementation of HashMap in Java and am stuck at one point.
How is the indexFor function calculated?
static int indexFor(int h, int length) {
return h & (length-1);
}
...
64
votes
3
answers
23k
views
How do I create a HashCode in .net (c#) for a string that is safe to store in a database?
To quote from Guidelines and rules for GetHashCode by Eric Lippert:
Rule: Consumers of GetHashCode cannot rely upon it being stable over time or across appdomains
Suppose you have a Customer ...
34
votes
5
answers
198k
views
How to compare two java objects [duplicate]
I have two java objects that are instantiated from the same class.
MyClass myClass1 = new MyClass();
MyClass myClass2 = new MyClass();
If I set both of their properties to the exact same values and ...
46
votes
3
answers
36k
views
What is a best practice of writing hash function in java?
I'm wondering what is the best practice for writing #hashCode() method in java.
Good description can be found here. Is it that good?
15
votes
8
answers
82k
views
How do I create a hash table in Java?
What is the most straightforward way to create a hash table (or associative array...) in Java? My google-fu has turned up a couple examples, but is there a standard way to do this?
And is there a ...
10
votes
8
answers
14k
views
Java hashCode for a Point class
I have a simple custom Point class as follows and I would like to know if my hashCode implemention could be improved or if this is the best it's going to get.
public class Point
{
private final ...
6
votes
5
answers
10k
views
How HashMap retrieves different values if Key's hashcode is same but equals method return false
I'm not able to understand on working pattern of HashMap. Kindly help to understand it.
Say we have two objects Obj1 and Obj2 having same Hashcode as 1212. Now when we run "==" and equals it returns ...
9
votes
2
answers
29k
views
Good hashCode() Implementation
The accepted answer in Best implementation for hashCode method gives a seemingly good method for finding Hash Codes. But I'm new to Hash Codes, so I don't quite know what to do.
For 1), does it ...
20
votes
4
answers
9k
views
How to specialize std::hash<T> for user defined types?
The Question
What is a good specialization of std::hash for use in the third template parameter of std::unordered_map or std::unordered_set for a user defined type for which all member data types ...