Fix a bug in the hashing function

The previous version of the hashing function is purely based on the hash
of the defining fields, which would make different objects of difference
classes but the same defining fields having the same hash. Now it has
been fixed by adding the identity of the class as the first field of the
hash.