hashcode

How to compute the hashCode() from the object's address?

In Java, I have a subclass Vertex of the Java3D class Point3f. Now Point3f computes equals() based on the values of its coordinates, but for my Vertex class I want to be stricter: two vertices are only equal if they are the same object. So far, so good: class Vertex extends Point3f { // ... public boolean equals(Object other) ...

Is there any kind of hashCode function in javascript?

Basically what I'm trying to do is create an object of unique objects, a set. I had the brilliant idea of just using a JS object with objects for the property names. Such as, set[obj] = true; This works, to a point. It works great with string and numbers, but with other objects, they all seem to "hash" to the same value and access the ...

Error with no HashCode, Equals eclipse

Hi, I'm looking for a very specific eclipse plugin that will tell me if a class in my project is not implementing hashCode or/and equals methods. Does anyone know of such a plugin? Thanks ...

How do you determine equality for two JavaScript objects?

A strict equality operator will tell you if two object types are equal, however, is there any way to tell if two objects are equal, much like the hash code value in Java? This is similar to this question, but requires a more academic answer: http://stackoverflow.com/questions/194846/is-there-any-kind-of-hashcode-function-in-javascript...

What is the best algorithm for an overridden System.Object.GetHashCode?

In .NET System.Object.GetHashCode method is use in a lot of places throughout the .NET base class libraries. Especially when finding items in a collection fast or to determine equality. Is there a standard algorithm/ best practise on how to implement the GetHashCode override for my custom classes so I don't degrade performance? ...

Fastest way to hash a set of GUIDs

I have a list of n GUIDs and I need to hash them into a single value. This value could be the size of a Guid object or the size of an Int32, it doesn't really matter, but it does need to be statistically unique (say with a probably similar to MD5). So one approach could be to sort them, concatenate the bytes and take an MD5 hash of all...

Why is it important to override GetHashCode when Equals method is overriden in C#?

Given the following class public class Foo { public int FooId { get; set; } public string FooName { get; set; } public override bool Equals(object obj) { Foo fooItem = obj as Foo; return fooItem.FooId == this.FooId; } public override int GetHashCode() { // Which is preferred? ...

How to ensure hashCode() is consistent with equals()?

When overriding the equals() function of java.lang.Object, the javadocs suggest that, "it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes." The hascode method must retur...

GetHashCode Guidelines in C#

I read in the Essential C# 3.0 and .NET 3.5 book that: "GetHashCode()’s returns over the life of a particular object should be constant (the same value), even if the object’s data changes. In many cases, you should cache the method return to enforce this." Is this a valid guideline? I have tried a couple built-in types in .NET and the...

hashCode() method when equals() is based on multiple independent fields

i have a class whose equality is based on 2 fields such that if either one is equal then the objects of this type are considered equal. how can i write a hashCode() function for such an equals() so that the general contract of hashCode being equal when equals returns true is preserved? public class MyClass { int id; String name; ...

Implementing `hashCode()` for very simple classes

I have a very simple class with only one field member (e.g. String). Is it OK to implement hashCode() to simply return fieldMember.hashCode()? Or should I manipulate the field's hash code somehow? Also, if I should manipulate it, why is that? ...

Why GetHashCode is not a property like HashCode in .NET

Why GetHashCode is not a property like HashCode in .NET? ...

What is native implementation in Java

If we look at the Java Object class then we can find some of the methods like public native int hashCode(), protected native Object clone(), so my question is what are these natives and how do these methods work? ...

Is there a way to get a hashcode of a float with epsilon?

It is well known that comparing floats by == is usually a mistake. In a 3D-vector class (with float components X, Y, Z) i wrote, two vectors are considered equal if their distance is considered zero. public override bool Equals(object obj) { if (obj == null) { return false; } if (GetType () != obj.GetType ()) { return fal...

How do you get the "object reference" of an object in java when toString() and hashCode() have been overridden?

I would like to print the "object reference" of an object in Java for debugging purposes. I.e. to make sure that the object is the same (or different) depending on the situation. The problem is that the class in question inherits from another class, which has overriden both toString() and hashCode() which would usually give me the id. ...

C#: GetHashCode override of object containing generic array

I have a class that contains the following two properties: public int Id { get; private set; } public T[] Values { get; private set; } I have made it IEquatable<T> and overriden the object.Equals like this: public override bool Equals(object obj) { return Equals(obj as SimpleTableRow<T>); } publi...

Why do downloads for various projects have hashcodes or checksums?

I've never used the checksum when downloading various executables or zip files from the Internet. I know it is used to check for consistency and add a bit of security. But is it necessary for when you download from a respectable project like Apache or Microsoft. How many of us actually use the checksums or hashcodes to verify the cont...

hmac_sha256 in php and c# differ

Hello this is my PHP code: hash_hmac( "sha256", utf8_encode( $filename ), utf8_encode( $password ) ); and this is my C# code: var hmacsha256 = new HMACSHA256( Encoding.UTF8.GetBytes( password ) ); hmacsha256.ComputeHash( Encoding.UTF8.GetBytes( filename ) ); unfortunately both results differ. Can anyone give me a hint? ...

checksum/hash function with reversible property

I am looking for a specific hashcode that has the following properties. I dont know of any such hashcodes and I dont know if it is possible to do such a thing. Just wanted to put it out there and see what people say. I have two databases (loosely used term - dont think of SQL or anything of that sort), one master and one backup. There i...

Java Array HashCode implementation

This is odd. A co-worker asked about the implementation of myArray.hashCode() in java. I thought I knew but then I ran a few tests. Check the code below. The odd think I noticed is that when I wrote the first sys out the results were different. Note that it's almost like it's reporting a memory address and modifying the class moved ...