The hashcode tag has no wiki summary.
3
votes
2answers
65 views
Unique hashCode with two fields without order
I need a hashCode implementation in Java which ignores the order of the fields in my class Edge. It should be possible that Node first could be Node second, and second could be Node first.
Here is my ...
0
votes
4answers
44 views
why not just using GetHashCode in Equality? [duplicate]
given the person class:
class person
{
public string name;
public int age;
}
say, i override the class person`s GetHashCode method:
public override int GetHashCode()
{
unchecked
...
4
votes
5answers
63 views
Is it proper for equals() to depend only on an ID?
Let's suppose I have class User:
public class User {
private Long id;
private String name;
private Integer age;
private BigDecimal account;
// other fields, getters and setters
}
Is it ...
0
votes
2answers
31 views
HashSet adds duplicate objects
I have a HashSet which stores some Edges in a Graph.
Each Edge has two Nodes.
In the case the graph is undirected, adding the duplicate should fail:
Edge a = new Edge(new Node("aa"), new ...
0
votes
2answers
44 views
Did I override equals and hashcode correctly?
In my most recent question, I was informed that I needed to override my equals and hashcode method (among other things). So I took a bit of time to read a few articles and attempted to come up with a ...
0
votes
1answer
28 views
weighted distribution hash bits
I would like to ask, if there is weight distribution equation for hash function or not?
like in channel coding theory there was weight enumerator equation for reed-solmon which give you the number of ...
0
votes
1answer
44 views
Generating hashCode from multiple fields? [duplicate]
How do I generate a hashCode from two fields in my class?
For example, I want Pair classes with the same objects V to have the same hashCode:
public class Pair<V> {
V from, to;
}
Should ...
-4
votes
0answers
37 views
ArrayList contains dont work How can I fix it (Solved) [closed]
I read a txt with 2 way StreamReader and File.ReadAllText after add the list
foreach (string line in File.ReadAllText(@openFileDialog1.FileName).Split(','))
{
if ...
-2
votes
3answers
70 views
How to avoid inserting duplicate objects in List?
I have two employee objects
Employee e1 = new Employee("1");
Employee e2 = new Employee("1");
So how to avoid inserting this second object in following List
List<Employee> list = new ...
-2
votes
1answer
39 views
Hashing an array of {a, b, c, d, e}
I need a hash function for a table[49] of {a, b, c, d, e}. In my table there will be exactly one 'e', one 'd', 6 'a', 6 'b' and rest will be filled with 'c'. I have seen numerous hashcodes, but I'm ...
1
vote
3answers
46 views
Provide Implementations of equals, hashCode and compareTo methods for class
I have an exam and this was in the mock and im not quite sure how to go about it, this isn't homework its simply trying to understand how to do it. Thanks.
public class Book{
private final String ...
2
votes
2answers
127 views
hashCode with same elements but different values
This is my Heap 12 File i keep on getting an error on my hashCode()...
Please help, I am getting an assertion error when it should be even
It looks similar to my peer's codes and the tutors cannot ...
0
votes
1answer
69 views
Does Asp support Hash (bcrypt) Passwords like in PHP
Is there a way to use Hash (bcrypt) Passwords in ASP like in PHP... the following would be the code for PHP but what is the alternative for ASP .. is it the same and just change things around? does ...
0
votes
1answer
51 views
valid and efficient implementation of hashcode()
I have a class School:
public class School{
private int noOfTeachers;
private int noOfStudents;
//setters and getters....
public boolean equals(Object that){
//instance of ...
2
votes
3answers
74 views
Java: Duplicate objects getting added to set?
If I run the below code then the output is 2 which means that the set contains 2 elements. However I think that set should contain 1 since both the objects are equal based on hashcode() value as well ...
5
votes
3answers
135 views
Is java's hashCode() deterministic? [duplicate]
is java's hashCode() deterministic?
I try to implement a document search engine that uses the minhashing algorithm and I use hashCode to pre-hash words.
Is the same word going to get the same hash ...
0
votes
1answer
31 views
Hazelcast: should I override hashCode or equals to use in a map
This general question is mostly out of curiosity rather then a concern.
Should hashCode and equals for mapped entity be overridden to face basic Hazelcast features properly?
And is there a known ...
2
votes
5answers
140 views
two unequal objects with same hashcode
Hashcode() and equals() concept is
1) If two Objects are equal according to equal(), then calling the hashcode method on each of those two objects should produce same hashcode.
and other one is
...
1
vote
3answers
51 views
hashCode(), equals(Object) and compareTo(Class)
I've following the following Vertex class and it implements equals, hashCode and compareTo method. Even then my HashMap returns null. I don't know why?
public class Vertex implements ...
-2
votes
1answer
56 views
About Apache Commons EqualsBuilder and HashCodeBuilder and null values
The classes EqualsBuilder and HashCodeBuilder from the Apache Commons Lang library can be used for object comparison purposes.
E.g., one can test equality between two Person objects like follows:
...
2
votes
4answers
83 views
How to write hashCode method for a particular class?
I'm trying to generate a hashCode() method for my simple class but i'm not getting anywhere with it. I would appreciate any help. I've implemented the equals() method, which looks as follows, and ...
0
votes
3answers
60 views
Hashcode from reflection?
I have got
interface Module {
List<String> parse();
}
There are several implementations of the interface and in application I would like to have a HashSet<Module> which ensures ...
9
votes
1answer
87 views
How to get recognition of Java URI hashCode() bug that has been inappropriately denied
A fundamental part of the Java Object contract is that the hashCode() method should be consistent with the equals() method. This makes sense and is easy to understand: if two objects are "equal" in ...
0
votes
2answers
129 views
how to use map with two int values and one string key
I am supposed to create a public StudentDatabase() which should create an empty database without using an java api class or method. There is supposed to be a method:
public boolean add(String macid, ...
0
votes
0answers
31 views
Java7 System.identityHashCode performance
The scene:
I am using XStream, which uses System.identityHashCode a lot.
I have migrated from IBM Java 1.5 to Oracle Java 7
The problem:
I see a performance problem, and have identified that ...
2
votes
4answers
75 views
Difference between Objects.hashCode() and new Object().hashCode()?
What's the difference between these two code snippets?
Snippet 1:
Object o = new Object();
int i = Objects.hashCode(o);
Snippet 2:
Object o = new Object();
int i = o.hashCode();
0
votes
0answers
47 views
Hash functions over IP/TCP packets
I am working on packet hashing and trying to find the most suitable function for this on a software implementation.
Every packet is identified by the 5-tuple:
{Ipsrc,IP dst,TCP ...
0
votes
0answers
39 views
Identify music by it s data (not id3 tag)
I want to detect music(mp3 file) by it s data! it means for example, i have a database that includes 10 sec of many musics! i want to detect the music by comparing music file and database (not id3 ...
0
votes
1answer
67 views
Java: Cannot find symbol: variable Objects
I generated methods hashCode() and equals(Object obj) by netbeans insercode. In netbeans I can compile without errors, but when I compile it on my server with javac:
bangserver/Login.java:3: cannot ...
1
vote
1answer
21 views
what does jenkinshash in hadoop guarantee?
I know that jenkinshash produces an integer (2^32) for a given value. The documentation at this link:
http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/JenkinsHash.html
says
Returns:
a ...
0
votes
2answers
91 views
HashCode - What will happen if equal object happened to hash in the same bucket?
I know this has been asked many times, but I can't find an exact answer to my question.
In chapter 3 of Effective Java, there is a scenario there that shows and explains why hashcode should be ...
2
votes
1answer
75 views
Hashcode generated by Eclipse
In SO I have read several answers related to the implementation of hashcode and the suggestion to use the XOR operator. (E.g. Why are XOR often used in java hashCode() but another bitwise operators ...
0
votes
2answers
38 views
How to generate a document ID or Report ID of 8 characters in .net
Can someone point me to the preferred method for generating a report or document ID? I have been looking at maybe using a guid that would be reduced down to a shorter length. We have an application ...
0
votes
2answers
63 views
Compare Objects' properties using hashcode
I need to know the ways to compare many objects using hashcode. So here is one of the class.
public class Test: IEquatable<Test>
{
public Test()
{
}
public string ID { get; ...
0
votes
1answer
36 views
get hash code from mp3 file
how can i get A hash code from mp3 file with this property:
No different between result for same mp3 files with bit rates highest than 8.
Id3 tags do not affect the result.
thanks.
1
vote
2answers
124 views
Why is the default hashcode() in java bad?
if I remember correctly the default hashCode() implementation in java of an object of type Object() is to return the memory address of the object. When we create our own classes, I read that we want ...
0
votes
1answer
38 views
java hashCode() function on reference variable and objects
For example, if I create an A type object,
A a = new A();
then a is a reference on the Stack that points to a A type object on the heap.
My question is, if I call a.hashCode(), which one's hash ...
3
votes
5answers
153 views
Java overriding equals() and hashcode() for two interchangeable integers
I'm overriding the equals and hashcode methods for a simple container object for two ints. Each int reflects the index of another object (it doesn't matter what that object is). The point of the class ...
2
votes
1answer
58 views
Compute hashCode for OR logic
I have an object acting as a unique identifier, that has two parameters, we'll call them A and B, and has the following logic:
obj1 is equal to obj2 if and only if:
obj1.A is equal to obj2.A
OR
...
0
votes
0answers
79 views
Boost::hash_range vs. Java's hash code
I'm looking for an efficient hash algorithm with which I can have 64-bit values represent strings in a databse.
Following Mark Adler's answer+comments here it seems that using a cryptographical hash ...
0
votes
1answer
47 views
How to use a String in an Entity class hash code?
I'm making a web app that queries an SQL db. I'm under the impression that I need to use entity classes and facade classes to allow persistence - across the whole site. The entity class templates ...
0
votes
1answer
43 views
How is data retrieved from a HashTable in collision?
According to this, time complexity of search in a hashtable is O(1).
However if there is a collision, then obviously this should be O(1) + something.
My question is:
When you say
get(someKey)
...
3
votes
2answers
119 views
Java and string.hashCode() stability across machines in cluster [duplicate]
I have asked similar question for the string.GetHashCode() method in .NET. Taken from then, I have learned that we cannot rely on the implicit implementation of hash code for the buit-in types, if we ...
5
votes
4answers
154 views
Overriding hashCode with overridden equals using equalsIgnoreCase to check equality
I've currently got an overridden equals(Object) that looks like this:
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (! (o instanceof Player)) return false;
...
0
votes
1answer
141 views
Same String, different hash codes
I am coding a simple lookup that somehow always fails. Investigating further, I have found something I can't explain: It seems that while my strings are identical, they don't get the same hash code.
...
0
votes
2answers
44 views
How to define a hashcode for class having 3 byte[]?
How should I define a hashCode for a class having 3 byte[]?
public class Key implements Comparable<Key> {
private static final long serialVersionUID = 1L;
private byte[] subKey1;
...
0
votes
1answer
557 views
JPA-Hibernate exception “could not get a field value by reflection getter” on persist
I have a Spring 3.2.1, Hibernate 4.1.9 and Spring Data application. I am using inheritance type joined for my entities and the hierarchy is as follows: a superclass DomainEntity and two classes ...
6
votes
1answer
138 views
What's behind the hashCode() method for String in Java? [duplicate]
I've been investigating the hashCode() methods in java and found the one for String class strange. The source code is as follows:
public int hashCode() {
int h = hash;
if (h == 0 && ...
1
vote
1answer
92 views
Custom Class Used in A List/HashSet
I have a custom class that looks like below:
public class customClass(){
private int keyCode;
private boolean up;
private String toTrigger;
public String getTrigger();
public ...
10
votes
4answers
206 views
Java: A “prime” number or a “power of two” as HashMap size?
Many books and tutorials say that the size of a hash table must be a prime to evenly distribute the keys in all the buckets. But Java's HashMap always uses a size that is a power of two. Shouldn't it ...