hashcode* ( depth obj -- code )
Factor handbook > The language > Collections > Hashtables > Hashtable keys

Prev:hashcode ( obj -- code )
Next:identity-hashcode ( obj -- code )


Inputs and outputs
depthan integer
objan object
codea fixnum

Generic word contract
Outputs the hashcode of an object. The hashcode operation must satisfy the following properties:
If two objects are equal under =, they must have equal hashcodes.
If the hashcode of an object depends on the values of its slots, the hashcode of the slots must be computed recursively by calling hashcode* with a level parameter decremented by one. This avoids excessive work while still computing well-distributed hashcodes. The recursive-hashcode combinator can help with implementing this logic,
The hashcode should be a fixnum, however returning a bignum will not cause any problems other than potential performance degradation.
The hashcode is only permitted to change between two invocations if the object or one of its slot values was mutated.

If mutable objects are used as hashtable keys, they must not be mutated in such a way that their hashcode changes. Doing so will violate bucket sorting invariants and result in undefined behavior. See Hashtable keys for details.

See also
hashcode, identity-hashcode


GENERIC: hashcode* ( depth obj -- code )