Questions tagged [hash-code-uniqueness]

Use this tag for questions related to a Hash Code's Uniqueness, i.e. when the hash codes are unique.

is used in its general meaning, so you are advised to use one or more additional tags to best describe your specific case.

45 questions
3
votes
5 answers

Is it a good approach to generate hash codes?

I have to write a hash function, under the following two conditions: I don't know anything about Object o that is passed to the method - it can be a String, and Integer, or an actual custom object; I am not allowed to call hashCode() at…
Nikita
  • 769
  • 2
  • 8
  • 18
3
votes
3 answers

What is the use of overriding hashCode in Java other than Collections API?

This question is asked by interviewer that most of answers related to hash code is used for bucketing where it checks equals to search objects. Is there any other general use case or scenario, where hash code is beneficial and can be used in a…
fatherazrael
  • 5,511
  • 16
  • 71
  • 155
3
votes
1 answer

Object Identity and Equality in Java

Please take a look at the 2 examples below: String a = new String("hello"); String b = new String("hello"); System.out.println("a.hashCode() - " + a.hashCode()); System.out.println("b.hashCode() - " + b.hashCode()); System.out.println("a == b - " +…
user9525103
3
votes
2 answers

.Net C# String.GetHashCode() alternative

I have problem with comparing lot of string data (csv files). These files has uniqueID but are not sorted and they are quite big. So I tried to create two dictionaries where key is uniqueID from file and Value is int which returns GetHashCode() of…
avojacek
  • 35
  • 1
  • 5
2
votes
2 answers

Java hashcodes collide in one case and not the other for the same objects, why? (Code Below)

I tried to write a small program to demonstrate hash collisions in java when only equals is overridden and not hashcode() method. This was to prove the theory that two unequal objects can have the same hashcode. This was for an Interview question…
Sameer
  • 757
  • 1
  • 14
  • 35
2
votes
3 answers

generating hashcode with already unique integer

Simple question. I have an object: class User { int id; String username; public User() { } public User(int id, String username) { this.id = id; this.username = username; } @Override public String…
ryvantage
  • 13,064
  • 15
  • 63
  • 112
2
votes
2 answers

How to handle image filename duplication in scrapy image download

Scrapy uses sha1 to generate random image filename. When duplication occurs, it will overwrite the file, causing loss of an existing image file. Is it possible to write extra code (e.g: an overriding class) to handle duplication. For instance: keep…
Harry
  • 570
  • 2
  • 10
  • 19
1
vote
2 answers

setting hashcode and equals to create a set with unique object

I would create a Set exactly HashSet to contains only char.for example a,b,c,d,e,f,g... but these chars are not represented by the primitive type but I have an object public FirstChar{ private char c; public FirstChar(char c){ this.c =…
Mazzy
  • 13,354
  • 43
  • 126
  • 207
1
vote
1 answer

UUID for a page content in AEM across author and it's associated publish servers are different

A page in author with UUID(jcr:uuid) is activated and its content is replicated onto the 3 associated publish servers. The content available in all the 3 publish servers has different UUIDs. So, considering the same content across all the 4…
1
vote
14 answers

Why are the hash codes generated by this function not unique?

I'm testing the VB function below that I got from a Google search. I plan to use it to generate hash codes for quick string comparison. However, there are occasions in which two different strings have the same hash code. For example, these…
Martin08
  • 20,990
  • 22
  • 84
  • 93
1
vote
2 answers

Uniqueness of hashcode for Java's HashSet and its subsets

If I have a Java HashSet with a length ranging from 1 to 10.000, are the hash codes of this set and all of its subsets unique?
Marcu Daniel
  • 85
  • 2
  • 11
1
vote
2 answers

How to verify an instance of a List is not another List instance?

I have a list var theDataList: List // populated with some data and made a copy of it val copy = theDataList.toMutableList() downstream in the code it would like to verify whether it is the copy one or the original one the .hashCode()…
lannyf
  • 9,865
  • 12
  • 70
  • 152
1
vote
1 answer

Simple hashcode in hashmap misconception?

I am implementing my own specialized hashmap which has generic value types, but keys are always of type long. Here and there, I am seeing people suggesting that I should multiply key by a prime and then get modulo by number of buckets: int bucket =…
vlada
  • 155
  • 1
  • 2
  • 12
1
vote
2 answers

C# GetHashCode Implementation

Is public override int GetHashCode() { return Word.GetHashCode(); } Really the same to public override int GetHashCode() { return (int) Word.GetHashCode() * 7; } regarding the uniqueness? Word is of type String EDIT: I forgot to say,…
Hendrik Breezy
  • 128
  • 1
  • 12
1
vote
1 answer

which hash functions are orthogonal to each other?

I'm interested in multi-level data integrity checking and correcting. Where multiple error correcting codes are being used (they can be 2 of the same type of codes). I'm under the impression that a system using 2 codes would achieve maximum…