In my application I need to compute a hash of a given .NET assembly and of a given type.
Assemblies and types to hash are loaded dynamically in this scenario.
Object's built-in method GetHashCode returns different value each time an application is started.
How to compute a deterministic hash function of an assembly or a type?
Any a...
Possible Duplicate:
How does Object.GetHashCode work when the GC moves an object?
The garbage collector in .NET moves objects, so the object's address is not stable. How is Object's GetHashCode() method implemented?
Thanks!
...
I have a class that internally is just an array of integers. Once constructed the array never changes. I'd like to pre-compute a good hashcode so that this class can be very efficiently used as a key in a Dictionary. The length of the array is less than about 30 items, and the integers are between -1000 and 1000 in general.
...
Hi, I am running into a question about equals and hashCode contracts:
here it is
Given:
class SortOf {
String name;
int bal;
String code;
short rate;
public int hashCode() {
return (code.length() * bal);
}
public boolean equals(Object o) {
// insert code here
}
}
Which of the following will fulfi...
Here I have some value which two of them are integer and I can't call a method on them since they are not reference. How can I solve this?
String srcAddr, dstAddr, protocol;
int srcPort, dstPort;
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dstAddr == null) ? 0 : dst...
I have a Employee class with many attributes. One of the attributes is employeeId which is of type int.
Can I have hascode function for Employee as follows?
int hashCode(){
return new Integer(employeeId).hashCode();
}
Is it efficient?
...
Hi There,
Edit: Prepare my objects for the use within a HashMap.
after reading a bit about how to generate a hash code, im kind of confused now. My (probably trivial) question is, how should I implement a hashCode method when I have one field that I could use? Can I use the fiels directly?
IIUC the values for hashCode must not change ...
Hi,
I have this simple class
public class Position{
int x;
int y;
Position(int x,int y){...}
public int hashCode(){
Integer ix = this.x;
Integer iy = this.y;
return 13*iy.hashCode() + 43*ix.hashCode();
}
}
Im storing instances in a hashMap, but then cant retrieve them. I fear its the hashcode implementat...
How can I generate a hash code for an object based on its identity.
What I mean is that:
if object.ReferenceEquals(a, b) == true, then a and b will get the same hash code.
if object.ReferenceEquals(a, b) == false, then a and b should have a decent chance to get different hash codes even if they are memberwise equal.
What I have is:
...
I have a big dictionary where the key is decimal, but the GetHashCode() of System.Decimal is disasterously bad. To prove my guess, I ran a for loop with 100.000 neigboring decimals and checked the distribution. 100.000 different decimal numbers used only 2 (two!!!) different hashcodes.
Decimal is represented as 16 bytes. Just like Guid!...
In java obj.hashcode() return somevalue.My question is what is the use of this hash code in programming?
...
Hey so I'm sorry if this is really obvious but I was just wondering why is that primes are used in a class's hashCode() method? For example, when using Eclipse to generate my hashCode() method there is always the prime number 31 used:
public int hashCode() {
final int prime = 31;
//...
}
Thanks in advance!!
...
The following code results in the same hash code being generated for the two maps, any ideas?
import java.util.HashMap;
import java.util.Map;
public class Foo
{
@SuppressWarnings("unchecked")
public static void main (String[] args)
{
Map map;
map = new HashMap();
map.put("campaignId", 4770L);
...
The title of the question says it all. I have been researching SHA-1 and most places I see it being 40 Hex Characters long which to me is 640bit. Could it not be represented just as well with only 10 hex characters 160bit = 20byte. And one hex character can represent 2 byte right? Why is it twice as long as it needs to be? What am I miss...
I'm curious why Object.toString() returns this:
return getClass().getName() + "@" + Integer.toHexString(hashCode());
as opposed to this:
return getClass().getName() + "@" + hashCode();
What benefits does displaying the hash code as a hex rather than a decimal buy you?
...
I have set up a circular linked list data structure that represents a word, and each element in the list is a letter from the word. At the bottom of my question are the class definitions of the list and element of the list.
The purpose of the list data structure is to be able to compare cyclic words. So... "picture" and "turepic" are th...
I have a Java HashMap whose keys are instances of java.lang.Object, that is: the keys are of different types. The hashCode values of two key objects of different types are likely to be the same when they contain identical variable values.
In order to improve the performance of the get method for my HashMap, I'm inclined to mix the name ...
from p.46 "Effective Java" Joshua Bloch. Item 9: ALways override hashCode when you override equals
Some class PhoneNumber overrides equals() and doesn't override hashCode()
"two instances are involved: one is used for insertion into the HashMap, and a second, equal, instance is used for (attempted) retrieval."
...
"... Even if the two ...
I know the ideal hashcode algorithm is a research area, but what sensible things can I do to minimise collisions and why do they work?
For example, I've seen hashcode functions that make use of prime numbers, but I'm not clear on what the benefit is...
...
I was playing around with Dictionary and stumbled across the below scenario
public class MyObject
{
public string I { get; set; }
public string J { get; set; }
public string K { get; set; }
public override int GetHashCode()
{
int hashCode = (I+J+K).GetHashCode();
Debugger.Log(9, "INFO", hashCode.ToSt...