1
$\begingroup$

I have a hash table that uses zobrist hashing to calculate the hash for various positions. The hash table is used to look up various transpositions. For some positions I do not want to allow any transpositions, but I still want to store the position in the hash table. So I'm trying to make the position's hash unique by XOR'ing it with the memory address of the object that holds the position structure. Here is some pseudocode:

hash = zobristHash(position);
if (makeItUnique)
    hash := h XOR [memory address of position object]

Is there any reason to suppose that what I'm doing will increase the likelihood of hash collisions?

$\endgroup$
  • $\begingroup$ Sorry, I don't understand what you are asking. What do you mean by "put them in the cache" or "make them unique"? It's not clear what "them" refers to. Please edit the question. C++ coding questions are off-topic here. Not everyone here reads C++, and if the answer depends on the behavior of reinterpret_cast<quint64>, the question is off-topic here. $\endgroup$ – D.W. May 3 at 15:39
  • $\begingroup$ Ok, thanks for suggestions. I've edited to use pseudocode and hopefully to be more clear. $\endgroup$ – Yeshe Tenley May 3 at 16:12
1
$\begingroup$

it may be better to store them in separate hash table. or, if you need them in the same table:

tmp = position
if (makeItUnique)
    tmp := [memory address of position object]
hash = zobristHash(tmp);

It's better than your current code since it will avoid collisions of objects with the same position AND similar memory address (the definition of similarity here depends on how you use the hash value to address the hash table)

| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

I don't see any reason to expect this to increase the chance of collisions. If the data in the object and the address of the object are independent, then XOR does not cause any harm.

It might be even simpler and faster to use a hash of the address, without hashing the object contents, when you want it to be unique.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ about just using the hash of the address... i was worried this would result in collisions that use pure zobrist hash so I decided to XOR memory address with zobrist hash, but perhaps i was seeing ghosts $\endgroup$ – Yeshe Tenley May 3 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.