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
167
votes
2 answers

Why is '397' used for ReSharper GetHashCode override?

Like many of you, I use ReSharper to speed up the development process. When you use it to override the equality members of a class, the code-gen it produces for GetHashCode() looks like: public override int GetHashCode() { unchecked …
programmer
  • 4,342
  • 4
  • 24
  • 21
24
votes
6 answers

Probability of getting a duplicate value when calling GetHashCode() on strings

I want to know the probability of getting duplicate values when calling the GetHashCode() method on string instances. For instance, according to this blog post, blair and brainlessness have the same hashcode (1758039503) on an x86 machine.
Diego
  • 1,531
  • 1
  • 15
  • 27
13
votes
5 answers

Are hash collisions with different file sizes just as likely as same file size?

I'm hashing a large number of files, and to avoid hash collisions, I'm also storing a file's original size - that way, even if there's a hash collision, it's extremely unlikely that the file sizes will also be identical. Is this sound (a hash…
SqlRyan
  • 33,116
  • 33
  • 114
  • 199
12
votes
5 answers

Are there circumstances where a hash algorithm can be guaranteed unique?

If I'm hashing size-constrained similar data (social security numbers, for example) using a hash algorithm with a larger byte size than the data (sha-256, for example), will the hash guarantee the same level of uniqueness as the original data?
matt
  • 121
  • 1
  • 3
10
votes
6 answers

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 is to represent a connection between the two…
Twice Circled
  • 1,410
  • 1
  • 15
  • 23
9
votes
8 answers

Java hashCode for a Point class

I have a simple custom Point class as follows and I would like to know if my hashCode implemention could be improved or if this is the best it's going to get. public class Point { private final int x, y; public Point(int x, int y) { …
Victor Parmar
  • 5,719
  • 6
  • 33
  • 36
8
votes
5 answers

How to generate a hash code from three longs

I have a HashMap with coordinates as keys. Coordinates have 3 longs holding the x, y and z coordinate. (Coordinate is and needs to be a custom class, the coordinates need to be longs). Now i want to be able to access e.g. the field [5, 10, 4] by…
Samuel
  • 18,286
  • 18
  • 52
  • 88
7
votes
1 answer

Is the uniqueness of CRC-32-hashes sufficient to uniquely identify strings containing filenames?

I have sorted lists of filenames concatenated to strings and want to identify each such string by a unique checksum. The size of these strings is a minimum of 100 bytes, a maximum of 4000 bytes, and an average of 1000 bytes. The total number of…
MCH
  • 415
  • 3
  • 11
7
votes
4 answers

Tinyurl-style unique code: potential algorithm to prevent collisions

I have a system that requires a unique 6-digit code to represent an object, and I'm trying to think of a good algorithm for generating them. Here are the pre-reqs: I'm using a base-20 system (no caps, numbers, vowels, or l to prevent confusion and…
Dan Breen
  • 12,626
  • 4
  • 38
  • 49
6
votes
3 answers

Can I assume two objects with the same System.identityHashCode are the same?

Though two different objects may have the same hash code, however, System.identityHashCode() seems return the memory pointer of the object. I guess there could be no exception in 32-bit JVM implementations, includes Sun JDK, Open JDK. I didn't check…
Lenik
  • 13,946
  • 17
  • 75
  • 103
5
votes
3 answers

Will this hash function collide unusually frequently?

I had the following code to generate a hash of an object: public int GetHashCode(MyType obj) { return (obj.Prop1.GetHashCode() + obj.Prop2.GetHashCode() + obj.Prop3.GetHashCode()).GetHashCode(); } I.e. I add all the properties' hash codes and…
Xodarap
  • 11,581
  • 11
  • 56
  • 94
5
votes
2 answers

Dynamic perfect hashing and universal hash functions - explanation please?

So I'm reading up about hash tables, hash functions etc. I was intrigued to read on wikipedia about how "dynamic perfect hashing" involves using a second hash table as the data structure to store multiple values within a particular bucket. Where I…
Ray
  • 3,468
  • 8
  • 26
  • 27
5
votes
5 answers

what really happens when passing objects in java?

I know when we are passing objects we are passing its reference as a value. But this value you get is using the hashcode() method right (according to my tests it's the same)? Since hashcode() is not the memory address and not guaranteed to get…
samsamara
  • 4,630
  • 7
  • 36
  • 66
4
votes
1 answer

Fast HashCode of a Complex Object Graph

I have a pretty complex object and I need to get uniqueness of these objects. One solution can be done by overriding GetHashCode(). I have implemented a code noted below: public override int GetHashCode() { return…
Abdul Munim
  • 18,869
  • 8
  • 52
  • 61
4
votes
4 answers

Is a hash result ever the same as the source value?

This is more of a cryptography theory question, but is it possible that the result of a hash algorithm will ever be the same value as the source? For example, say I have a string: baf34551fecb48acc3da868eb85e1b6dac9de356 If I get the SHA1 hash on…
SqlRyan
  • 33,116
  • 33
  • 114
  • 199
1
2 3