Linked Questions
308 questions linked to/from What is the best algorithm for overriding GetHashCode?
36
votes
6
answers
61k
views
Overriding GetHashCode [duplicate]
As you know, GetHashCode returns a semi-unique value that can be used to identify an object instance in a collection. As a good practice, it is recommended to override this method and implement your ...
75
votes
1
answer
92k
views
Implementing GetHashCode correctly [duplicate]
I'd like to hear from the community on how I should go about implementing GetHashCode (or override it) for my object. I understand I need to do so if I override the equals method. I have implemented ...
10
votes
1
answer
13k
views
Implementing GetHashCode [duplicate]
Possible Duplicate:
What is the best algorithm for an overridden System.Object.GetHashCode?
What constitutes a good implementation of the GetHashCode method? I did some googling, and found some ...
12
votes
2
answers
12k
views
Custom type GetHashCode [duplicate]
Possible Duplicate:
What is the best algorithm for an overridden System.Object.GetHashCode?
I need to override GetHashCode method for a type which consists of three strings. Here is my code:
...
12
votes
2
answers
7k
views
Why is the xor operator used in computing hash code? [duplicate]
In this MSDN article
http://msdn.microsoft.com/en-us/library/ms132123.aspx
it discusses the Class Equalitycomparer and has an example.In this example about comparing boxes it has this class -
class ...
7
votes
1
answer
10k
views
Creating a unique hash code based on some properties of an object [duplicate]
I have to following classes:
public class NominalValue
{
public int Id {get; set;}
public string ElementName {get; set;}
public decimal From {get; set;}
public decimal To {get; set;} ...
3
votes
1
answer
6k
views
C# GetHashCode() High Performance Hashing Algorithm [duplicate]
Possible Duplicate:
What is the best algorithm for an overridden System.Object.GetHashCode?
This is known to us that if we override the Equals method of Object in our custom types, we should also ...
2
votes
1
answer
4k
views
How to generate a unique Hashcode? [duplicate]
So, I have this Struct. It has some functions and operators overridden, but that's not so important.
public struct Vector3
{
public float X, Y, Z;
}
I'm filtering a Collection of these via a ...
2
votes
1
answer
6k
views
How to implement GetHashCode for a pair of 3D vectors [duplicate]
First of all, I found an implementation of GetHashCode for a 3D integer vector, but I can't figure out if this is a good one or not (at least I'm not 100% sure):
public struct Vector3i
{
public ...
3
votes
2
answers
3k
views
Using byte array as dictionary key [duplicate]
I want to use a byte array as a lookup key in a concurentDictionary.
Currently I solve this by using a custom EqualityComparer<byte[]>.
This works fine, but I do realize that my hashcode ...
1
vote
1
answer
3k
views
HashSet<T>.Contains is fast but I need to search for multiple properties of an object [duplicate]
I have a
var itemList = new List<Item>()
and a
var searchSet = new HashSet<TestItem>(new TestItemComparer());
For each element in the itemList I look for its existance in the ...
4
votes
1
answer
3k
views
How do you implement GetHashCode() on objects? [duplicate]
Duplicate: What is the best algorithm for an overridden System.Object.GetHashCode?
If you've written an object with a variety of data-members, how do you intelligently implement GetHashCode()?
One ...
2
votes
1
answer
2k
views
C# GetHashCode with three Int16 values? [duplicate]
I'm using this function for a key in C#'s hash map like class, "Dictionary".
x, y and z are Int16.
public override int GetHashCode()
{
return (x << 16) | (UInt16)y;
}
How could I extend ...
3
votes
2
answers
806
views
Why GetHashCode method needs to do shift in C# [duplicate]
According to MSDN GetHashCode Method:
public struct Point
{
private int x;
private int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public ...
0
votes
1
answer
1k
views
How to implement GetHashCode() in a C# struct [duplicate]
I have a struct that overrides the Equals() method and the compiler complains about GetHashCode() not being overridden.
My struct:
private struct Key
{
...
public override int ...