Questions tagged [hashcode]
A hash code is a result of applying a hash function to data, usually resulting in an integer.
2,028
questions
0
votes
1
answer
25
views
How to write equals method using Apache commons-lang3?
package org.sudoku;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.util.*;
public class SudokuBoard {
private final ...
-1
votes
0
answers
57
views
hashcode and equals - Java [duplicate]
Consider this class:
public class Employee {
private int empNumber;
private String name;
@Override
public int hashCode() {
return empNumber;
}
public Employee(int ...
1
vote
2
answers
41
views
median with hash table in sas 9.4
I want to calculate a median by groups for 100 variables with hash tables.
I have find this to calculate the median of invoice on sashelp.cars, but if I want to do the median by Make and Model, for ...
-1
votes
1
answer
41
views
How to use equals & hashcode from generic parent class in child classes? [closed]
I have many Entity classes in my project, and to avoid overriding the equals and hashCode methods in each one, I want to inherit them from a parent class where these methods are already implemented. ...
0
votes
1
answer
25
views
Implementing java's `HashCode` in Presto/Trino
I am trying to find a method in SQL world (specifically Trino/Presto) where I can reproduce the following Input / Output combination.
Input - s (type String)
Output - o Int where o = hashCode(s)
E.g.
...
0
votes
4
answers
65
views
since java creates a new object when new keyword is used, and every object has unique hashcode, then why here it is giving same hashcode output?
public class Main {
public static void main(String[] args) {
String str1="shrey";
String str2="shrey";
String str3=new String("shrey");
...
1
vote
0
answers
74
views
Why is int.MinValue.GetHashCode() == int.MaxValue.GetHashCode() is false, but Int64.MinValue.GetHashCode() == Int64.MaxValue.GetHashCode() is true?
Why is int.MinValue.GetHashCode() == int.MaxValue.GetHashCode() is false, but Int64.MinValue.GetHashCode() == Int64.MaxValue.GetHashCode() is true?
For both 32-bit integer and 64-bit integer, MinValue ...
3
votes
1
answer
89
views
How do I find three different strings with hash collisions, without using a brute force approach?
I've seen the following question for a hiring interview:
How do you find three different strings that have the same hash code in C#?
In other words, given the strings a, b, and c, the following four ...
1
vote
1
answer
96
views
In Java, during Object#equals() call, do both objects necessarily have same hashCode ? Do we need to ever compare hashCode within equals()?
I have read somewhere, in context of HashMap :
hashCode() allows sorting objects by their hash values, and then the Object#equals method only needs to be invoked when objects share the same hash value....
0
votes
0
answers
96
views
Yet Another Implementation of JPA Entity equals()/hashCode()
The history of the JPA entity equals() and hashCode() methods started a long ago. There is a ton of discussions, just google for the "jpa equals hashcode" and you'll find a brilliant Vlad ...
0
votes
2
answers
78
views
Understanding JVM Behavior: How Does `switch` Handle String Hash Collisions?
During an interview, I was posed an intriguing question about how the Java Virtual Machine (JVM) handles a switch statement involving a String type. Specifically, I was asked whether the JVM employs ...
1
vote
2
answers
76
views
Two different HashMap returning the same hashCode
I have two different sets of HashMap ({u=0, h=3} and {t=3, i=0}), and it is returning the same hashCode (224). I don't understand this, hashCode needs to be different for different objects, and here ...
1
vote
1
answer
54
views
Many to one hash function
I don't know exactly what to call it and this is the closest thing that I can think of
What I'm looking for is a function that takes an array of strings and returns a hash string like the following
...
1
vote
1
answer
69
views
Why are 2 org.apache.hc.core5.http.Header not equal when created with the same content?
Why does
import org.apache.hc.core5.http.Header;
Assertions.assertEquals(new BasicHeader("name", "value", true), new BasicHeader("name", "value", true));
or
...
0
votes
0
answers
75
views
convert md5 hash output into integer in Teradata
is it possible to convert uuid column value to int value using MD5 or other any other hashing function in Teradata.
select hash_md5("HelloWorld") ==> 68E109F0F40CA72A15E05CC22786F8E6
...
1
vote
2
answers
120
views
Get hashcode of a HashSet based on the items present in the HashSet
I have a HashSet<T> and I want to get the hashcode of the HashSet<T> based on the items it contains. I am trying to identify a HashSet<T> based on it's values. I know I can use set ...
-2
votes
1
answer
104
views
i have a hash code which i gotta write at java [closed]
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class EmailDecoder {
public static void main(String[] args) {
String ...
1
vote
1
answer
30
views
Unique Seed based on values & order on a set of Parameters
I have to generate a unique "Hash" based upon an array of parameters. So far I've been using string builder to generate a unique string for every set of parameters, and then using ...
0
votes
0
answers
36
views
Updating entities with OneToMany mappings: Spring Data JPA
I have a requirement where I need to update the entities on either side of a ManyToMany mapping.
I have a InsurancePolicy entity-
@Entity
@Table(name = "insurance_policy")
@Setter
@...
1
vote
1
answer
143
views
How to get constant hashcode (Uint32 or Int32) for a string but being outside of a range
According to this article the official "GetHashCode" for a string is made randomly per execution to prevent Hacking. But I need to persist the hashcode so I want it to be always the same per ...
1
vote
1
answer
327
views
Hashcat Combinator 3 word attack
I am able to do a two word combinator attack using Hashcat but when I try to add a third word list it does not work but no error is generated, only to use --help for assistance. Hashcat version is 6....
0
votes
1
answer
108
views
Generating three distinct strings with equal hashes using the default hash function in C#
I am trying to generate three distinct strings, A, B, and C, such that their hash values are all equal using the default hash function provided by the programming language. Specifically, I need to ...
2
votes
1
answer
133
views
Kotlin get default hashCode implementation for inherited class
Before overriding, each class in Kotlin/JVM has default equals/hashCode implementation. Equals is checking for reference equality with ===, but hashCode is something else (and I don't know what it is)....
0
votes
0
answers
55
views
Python hash() function not distributing uniformly?
I am experiencing an odd behavior with python's built-in hash() function.
I am writing hashes of strings (which come from various language/text datasets) into 900 different files, according to the ...
2
votes
1
answer
119
views
How is a 32-bit hashCode stored in a 25-bit mark word in Java without data loss?
I've been looking into the internals of Java objects and am puzzled about how hashCode values are managed. As I understand it, the hashCode method in Java returns a 32-bit integer. However, this ...
2
votes
2
answers
70
views
What is the key in the Set's underlying HashMap: hash code or the object itself?
Is this sentence from an OCP book correct?
A HashSet stores its elements in a hash table, which means the keys
are a hash and the values are an Object.
I have created below code snippet:
class A
{
...
0
votes
0
answers
98
views
reduceByKey giving different output between Spark 2 and Spark 3
I have the following code:
.flatMap {
case ((a, b), c) =>
aggregations.flatMap(definition =>
definition
.map(_
.distinct
...
0
votes
1
answer
37
views
Debugging an SBCL User-Defined Hash-table Test
I'm having trouble understanding an SBCL 2.3.2 error message involving a user-defined hash-table test. Also, is there a better/faster way to implement this?
debugger invoked on a TYPE-ERROR @2226541F ...
1
vote
0
answers
36
views
How to exclude some fields of subclasses from Apache Commons-> HashCodeBuilder.reflectionHashCode
I am trying to exclude some fields for a subclass during the hashcode generation, and it seems that either I have the option to exclude it entirely or none, but not the specific fields even after ...
0
votes
1
answer
24
views
Java - When does the hash code of an uninitialized array element get determined?
//1
int\[\]\[\] arr = new int\[2\]\[2\];
System.out.println(arr\[0\]); // \[I@7d6f77cc
System.out.println(arr\[1\]); // \[I@5aaa6d82
System.out.println(System.identityHashCode(arr\[0\])); // ...
0
votes
1
answer
72
views
Hash Code Builder generate duplicate hash code
I want to get 2 hash code of 2 difference group number as below but they have the same result. I can not understand why this happen. Please help to resolve this issue.
new HashCodeBuilder(17, 37)....
1
vote
2
answers
131
views
Can I cache getClass.hashCode()?
Whatever the reason, I have the following hashCode implemented in my abstract class.
@MappedSuperclass
abstract Some {
@Override
public boolean equals(final Object obj) {
// ...
}
...
1
vote
1
answer
331
views
Equals Verifier fails with error related to hashcode check for JPA entity
Given we have such class:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class User {
@Id
private Long id;
private String name;
private Integer age;
@...
1
vote
1
answer
128
views
.equals() on a PriorityQueue returns unexpected results
I'm sorry if this is a dumb question (especially for someone who has developed in java for over 4 years) or if it has been answered (I've searched stack overflow and despite the simplicity of the ...
0
votes
0
answers
37
views
Unique string representation of Expression<Func<T, bool>> and Func<IQueryable<T>, IIncludableQueryable<T, object>>
I'm having troubles implementing a cached repository:
I'd need to get a unique identifier for these 2 objects which are a Expression<Func<T, bool>> and Func<IQueryable, ...
1
vote
2
answers
125
views
How to correctly implement equals(), hashCode() if the values are within a range of each other?
The criteria is that equals() method where the objects are considered equal if the value of the double variable is within +/- 10 of the other object's value of the double variable.
I'm not sure how to ...
0
votes
1
answer
34
views
A special function for uids
I have an unique identifier (uid) x, and given an integer j, I need a function f such that f(x, j) is another uid (in the same "domain" as x) such that f(x, j1) = f(x, j2) if and only if j1 =...
-3
votes
2
answers
248
views
equals and hashCode with many fields in Java? [closed]
In Java apps, I prefer to use unique fields in equals and hashCode methods instead of adding only id field or all the fields. However, I am confused about the following points:
By considering object ...
0
votes
1
answer
111
views
Flutter: Why the hashCodes of the following container widgets are changing eveytime I hot-reload the app (save the file)?
If I run the following application and observe the hashCodes for BuildSizedBoxWidget which I create two instances of, I notice that they are the same even when I hot reload the app. Does this mean ...
1
vote
2
answers
361
views
Add unique elements in HashSet based on attributes of framework provided non-editable object classes
I am trying to generate a HashSet containing unique Employee instances. Uniqueness should be established based on the object properties.
The problem is that I end up with having duplicates.
Note that ...
4
votes
1
answer
129
views
Is Java ready for a HashCode record?
Records represent immutable state and are candidates for stack inlining.
If I declare a draft outline of a HashCode record, similar to a message digest class, like so:
public record HashCode(int value)...
-1
votes
2
answers
916
views
How does Java's Stream.distinct() select which of the duplicates to use
In Java let's say I have a class called Person. It has four properties:
Long personId
String name
int age
List<String> petNames
Let's say I have an array list variable of people called ...
0
votes
0
answers
24
views
Ask About This Hash / Encryption Combination is work
today i have a lil problem for recognize this combination hash is work, im looking when im log into my account in some apps, but i get this hash, and change everytime when i login, even with same ...
-1
votes
1
answer
261
views
Java Printing Hashcode instead of Content
I am trying to iterate inside some arrays containing the name, last name, id and the score of some student. I have to sort this array in descending format. I have used comparable function and compare ...
0
votes
3
answers
578
views
Flutter Equatable Real Life Usage?
I have learned that what is the Equatable and how can I use it. But I just wonder that why should I use it?
I have found some reasons. One of them, when we wants to compare 2 or more same object from ...
2
votes
2
answers
365
views
A Java string with hashCode equal to Integer.MIN_VALUE
Is there a known Java String with hashCode exactly equal to Integer.MIN_VALUE ? It would be helpful for writing a test for a hash table to help avoid a common mistake of running Math.Abs on the ...
0
votes
1
answer
53
views
Is it necessary to override hashcode method in non hashed datastructure
What I understand from hashcode method for objects in Java: it is required to calculate the hashcode of objects which in turn is used to calculate the index / bucket location of the object in a hashed ...
0
votes
0
answers
34
views
Maintaining a list of SocketChannels that are unique
I am using Java NIO and selectors to get instances of SocketChannels. I need to attach each instance of a SocketChannel that I get from the selector to an encryption key that is unique to each ...
0
votes
1
answer
202
views
Why does the identityHashCode function not work for the built-in type 'int' in Dart?
The documentation of the identityHashCode says:
And it indeed works for my custom type 'Integer':
class Integer {
int num;
Integer(this.num);
@override
int get hashCode {
return num;
}
...
1
vote
1
answer
311
views
Why am I not covering totaly hashcode test with lombok.Data
I am looking for the reason why jacoco is it showing me that i am not covering totaly my functions equals and hashCode.
I have this model code :
import lombok.Data;
@Data
public class Building2 {
...