hashcode

Two instances having the same hashcode but not equal

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-20 05:52:07
问题 I was reading the paragraph quoted below from an article entitled- Java theory and practice: Hashing it out - Defining hashCode() and equals() effectively and correctly Defining equality The Object class has two methods for making inferences about an object's identity: equals() and hashCode(). In general, if you override one of these methods, you must override both, as there are important relationships between them that must be maintained. In particular, if two objects are equal according to

Two instances having the same hashcode but not equal

十年热恋 提交于 2021-02-20 05:52:07
问题 I was reading the paragraph quoted below from an article entitled- Java theory and practice: Hashing it out - Defining hashCode() and equals() effectively and correctly Defining equality The Object class has two methods for making inferences about an object's identity: equals() and hashCode(). In general, if you override one of these methods, you must override both, as there are important relationships between them that must be maintained. In particular, if two objects are equal according to

Why would one add a constant to hashCode()? [duplicate]

懵懂的女人 提交于 2021-02-18 18:45:05
问题 This question already has answers here : Why does Java's hashCode() in String use 31 as a multiplier? (13 answers) Closed 2 years ago . I'm new to Java, and I've recently learned about hashCode() . On the wikipedia article about Java hashCode(), there is the following example of a hashCode() method: public class Employee { int employeeId; String name; Department dept; // other methods would be in here @Override public int hashCode() { int hash = 1; hash = hash * 17 + employeeId; hash = hash *

Why would one add a constant to hashCode()? [duplicate]

只愿长相守 提交于 2021-02-18 18:44:48
问题 This question already has answers here : Why does Java's hashCode() in String use 31 as a multiplier? (13 answers) Closed 2 years ago . I'm new to Java, and I've recently learned about hashCode() . On the wikipedia article about Java hashCode(), there is the following example of a hashCode() method: public class Employee { int employeeId; String name; Department dept; // other methods would be in here @Override public int hashCode() { int hash = 1; hash = hash * 17 + employeeId; hash = hash *

Duplicate Value in HashMap

南楼画角 提交于 2021-02-16 18:07:01
问题 I am in big trouble, created a hashMap and inserted two values with same key using StringBuilder as a key of map. Now, while trying to retrieve the data using StringBuilder object is working fine, but in other case its fails to return any value. I have listed three cases in the below given code, ` class MainClass { public static void main(String[] args) { MainClass m = new MainClass(); StringBuilder sb = new StringBuilder("sb"); StringBuilder sb1 = new StringBuilder("sb"); Map<StringBuilder,

Duplicate Value in HashMap

血红的双手。 提交于 2021-02-16 18:05:40
问题 I am in big trouble, created a hashMap and inserted two values with same key using StringBuilder as a key of map. Now, while trying to retrieve the data using StringBuilder object is working fine, but in other case its fails to return any value. I have listed three cases in the below given code, ` class MainClass { public static void main(String[] args) { MainClass m = new MainClass(); StringBuilder sb = new StringBuilder("sb"); StringBuilder sb1 = new StringBuilder("sb"); Map<StringBuilder,

Duplicate Value in HashMap

我的梦境 提交于 2021-02-16 18:05:11
问题 I am in big trouble, created a hashMap and inserted two values with same key using StringBuilder as a key of map. Now, while trying to retrieve the data using StringBuilder object is working fine, but in other case its fails to return any value. I have listed three cases in the below given code, ` class MainClass { public static void main(String[] args) { MainClass m = new MainClass(); StringBuilder sb = new StringBuilder("sb"); StringBuilder sb1 = new StringBuilder("sb"); Map<StringBuilder,

GetHashCode() override coliding way to often

本小妞迷上赌 提交于 2021-02-08 04:09:00
问题 I'm using unity, and unity does not have a tuple in it, so I created my own tuple class to work since I needed it for my Dictionary. Dictionary <Tuple<int,int>, Tile> Tile class that I created and isn't really relevant to solve this problem(at least I think it wont help). But the problem is that I'm using both negative and positive integer in my tuples, and when I use my current GetHashCode() with the Tuples , sometimes I get the same HashCode, for example Tuple<-10, 8> and Tuple<-9,-10> both

Generate a Hashcode for a string that is platform independent

こ雲淡風輕ζ 提交于 2021-02-05 06:11:02
问题 We have an application that Generates a hash code on a string Saves that hash code into a DB along with associated data Later, it queries the DB using the string hash code for retrieving the data This is obviously a bug because the value returned from string.GetHashCode() varies from .NET versions and architectures (32/64 bit). To complicate matters, we're too close to a release to refactor our application to stop serializing hash codes and just query on the strings instead. What we'd like to

Generate a Hashcode for a string that is platform independent

杀马特。学长 韩版系。学妹 提交于 2021-02-05 06:09:52
问题 We have an application that Generates a hash code on a string Saves that hash code into a DB along with associated data Later, it queries the DB using the string hash code for retrieving the data This is obviously a bug because the value returned from string.GetHashCode() varies from .NET versions and architectures (32/64 bit). To complicate matters, we're too close to a release to refactor our application to stop serializing hash codes and just query on the strings instead. What we'd like to