This is my understanding about hashcode and equals method :         if obj1.hashcode == obj2.hashcode (returns true) then obj1.equals(obj2) returns true and   if  obj1.equals(obj2) returns false (returns true) then obj1.hashcode == obj2.hashcode (returns false)      is this correct?
7577
What issues / pitfalls must be considered when overriding equals and hashCode?
3469
I came across this recently, up until now I have been happily overriding the equality operator (==) and/or Equals method in order to see if two references types actually contained the same data (i.e. two different instances that look the same). I have been using this even more since I have been getting more in to automated testing (comparing reference/expected data against that returned). While looking over some of the  I came across an  that advises against it. Now I understand why the article is saying this (because they are not the same instance) but it does not answer the question:  What is the best way to compare two reference types? Should we implement ? (I have also seen mention that this should be reserved for value types only). Is there some interface I don't know about? Should we just roll our own?!  Many Thanks ^_^ Update Looks like I had mis-read some of the documentation (it's been a long day) and overriding  may be the way to go..  If you are implementing reference types, you should consider overriding the Equals method on a reference type if your type looks like a base type such as a Point, String, BigNumber, and so on. Most reference types should not overload the equality operator, even if they override Equals. However, if you are implementing a reference type that is intended to have value semantics, such as a complex number type, you should override the equality operator.
89006
Are there any hash outputs not produced by the MD5 hash function? I need to use it as a placeholder for an empty hash while comparing two hashes.
7905
What is the difference between == and ===?  How exactly does the loosely == comparison work? How exactly does the strict === comparison work?  What would be some useful examples?
14775
There is a case where a map will be constructed, and once it is initialized, it will never be modified again.  It will however, be accessed (via get(key) only) from multiple threads.  Is it safe to use a java.util.HashMap in this way?  (Currently, I'm happily using a java.util.concurrent.ConcurrentHashMap, and have no measured need to improve performance, but am simply curious if a simple HashMap would suffice.  Hence, this question is not "Which one should I use?" nor is it a performance question.  Rather, the question is "Would it be safe?")
17859
Is there a known pair of distinct bit strings (A,B) such that SHA-1(A) == SHA-1(B)?  If the answer is no, then how can SHA-1 be considered broken?
80637
So I have a collection of objects.  The exact type isn't important.  From it I want to extract all the unique pairs of a pair of particular properties, thusly:  myObjectCollection.Select(item=&gt;new                                 {                                      Alpha = item.propOne,                                      Bravo = item.propTwo                                 }                  ).Distinct();   So my question is:  Will Distinct in this case use the default object equals (which will be useless to me, since each object is new) or can it be told to do a different equals (in this case, equal values of Alpha and Bravo => equal instances)?  Is there any way to achieve that result, if this doesn't do it?
98914
The MSDN documentation on  describes 3 contradicting rules for how the method should work.     If two objects of the same type represent the same value, the hash function must return the same constant value for either object. For the best performance, a hash function must generate a random distribution for all input. The hash function must return exactly the same value regardless of any changes that are made to the object.   Rules 1 &amp; 3 are contradictory to me.  Does Object.GetHashCode() return a unique number based on the value of an object, or the reference to the object. If I override the method I can choose what to use, but I'd like to know what is used internally if anyone knows.
80225
Evidently hash keys are compared in a case-sensitive manner.  $ perl -e '%hash = ( FOO =&gt; 1 ); printf "%s\n", ( exists $hash{foo} ) ? "Yes" : "No";' No  $ perl -e '%hash = ( FOO =&gt; 1 ); printf "%s\n", ( exists $hash{FOO} ) ? "Yes" : "No";' Yes   Is there a setting to change that for the current script?
1275
I'm using  to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals signs) when doing things like comparing idSele_UNVEHtype.value.length == 0 inside of an if statement.  Is there a performance benefit to replacing == with ===?   Any performance improvement would be welcomed as many comparison operators exist.  If no type conversion takes place, would there be a performance gain over ==?
17676
Is every output of a hash function (e.g. SHA1, MD5, etc) guaranteed to be possible, or, conversely, are there any output values that cannot possibly be created from any input? In other words, are hash functions surjective?  If so, what guarantees this? If not, is it possible to discover such impossible outputs via an attack faster than brute force?
42562
How could I go about detecting (returning true/false) whether an ArrayList contains more than one of the same element in Java?  Many thanks, Terry  Edit Forgot to mention that I am not looking to compare "Blocks" with each other but their integer values. Each "block" has an int and this is what makes them different. I find the int of a particular Block by calling a method named "getNum" (e.g. table1[0][2].getNum();
77207
I would like to write a function GetHashCodeOfList() which returns a hash-code of a list of strings regardless of order. Given 2 lists with the same strings should return the same hash-code.   ArrayList list1 = new ArrayList()     list1.Add("String1"); list1.Add("String2"); list1.Add("String3");      ArrayList list2 = new ArrayList()     list2.Add("String3");     list2.Add("String2");  list2.Add("String1");  GetHashCodeOfList(list1) = GetHashCodeOfList(list2) //this should be equal.   I had a few thoughts:    I can first sort the list, then combine the sorted list into 1 long string and then call GetHashCode(). However sorting is a slow operation. I can get the hash of each individual string (by calling string.GetHashCode()) in the list, then multiplying all hashes and calling Mod UInt32.MaxValue.  For example: "String1".GetHashCode() * "String2".GetHashCode * … MOD UInt32.MaxValue. But this results in a number overflow.   Does anyone have any thoughts?  Thanks in advance for your help.
105864
Say for a Point2 class, and the following Equals:  public override bool Equals ( object obj )  public bool Equals ( Point2 obj )   This is the one that is shown in the Effective C# 3:  public override bool Equals ( object obj ) {     // STEP 1: Check for null     if ( obj == null )     {         return false;     }      // STEP 3: equivalent data types     if ( this.GetType ( ) != obj.GetType ( ) )     {         return false;     }     return Equals ( ( Point2 ) obj ); }  public bool Equals ( Point2 obj ) {     // STEP 1: Check for null if nullable (e.g., a reference type)     if ( obj == null )     {         return false;     }     // STEP 2: Check for ReferenceEquals if this is a reference type     if ( ReferenceEquals ( this, obj ) )     {         return true;     }     // STEP 4: Possibly check for equivalent hash codes     if ( this.GetHashCode ( ) != obj.GetHashCode ( ) )     {         return false;     }     // STEP 5: Check base.Equals if base overrides Equals()     System.Diagnostics.Debug.Assert (         base.GetType ( ) != typeof ( object ) );      if ( !base.Equals ( obj ) )     {         return false;     }      // STEP 6: Compare identifying fields for equality.     return ( ( this.X.Equals ( obj.X ) ) &amp;&amp; ( this.Y.Equals ( obj.Y ) ) ); }
81455
Suppose I have a set of elements, with known hash (e.g. SHA-2). How can I calculate the hash of the set? With it I mean an unordered set, so the order of elements is undefined and shall not play any role in determining the hash of the set.  In theory any commutative operation applied to the hashes should be fine, but I have the strong feeling that XORing all of them together is quite unsafe. An attacker could add an element to the set to produce a hash collision, although finding an element with that wanted hash is as hard as breaking the hash of the whole set.  Anything better solution than the trivial one of sorting the elements into a list, calculating their hashes and then calculating the hash of the hash list?  I think Merkle trees can't help here if they are based on some sort of ordering of the elements.
2525
My  has failed me.  In Python, are the following two tests for equality equivalent?  n = 5 # Test one. if n == 5:     print 'Yay!'  # Test two. if n is 5:     print 'Yay!'   Does this hold true for objects where you would be comparing instances (a list say)?  Okay, so this kind of answers my question:  L = [] L.append(1) if L == [1]:     print 'Yay!' # Holds true, but...  if L is [1]:     print 'Yay!' # Doesn't.   So == tests value where is tests to see if they are the same object?
33449
First off, I know hashes are 1 way. There are an infinite number of inputs that can result in the same hash output. Why can't we take a hash and convert it to an equivalent string that can be hashed back to the original hash output?  eg:  string: "Hello World" hashed: a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e   unhash: "rtjwwm689phrw96kvo48rm64unc8oetb5kmrjiuh7h8huhi6dde5n5"         (a real string that gives the same hash as "Hello World") hashed: a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e    ...