1

During preprocessing of a SAT instance consisting of a clause database, every variable needs to be assigned a word. A hash function returns for each variable a 32-bit word only consisting of 0’s except for one bit among the 16 most significant bits (MSB) and one bit among the 16 least significant bits (LSB), which are set to 1 depending on the variable. The signature of a clause is the bitwise OR of all its variables’ hash function values.

How do I implement this hash function?

Realz Slaw
  • 3,138
  • 1
  • 24
  • 38

1 Answers1

1

Well, each half-word has 16 possibilities; the 1 can be in 16 places. This gives 16x16=256 possible "hashes". For variable count > 256, you will definitely have collisions. What you can do is pass v % 256 before passing it to the hash function. This is one possible such hash function:

unsigned int hash_variable(int v)
{
  v = v % 256

  assert(v < 256);

  unsigned char lower_nibble = v & 0x0f;
  unsigned char upper_nibble = (v & 0xf0) >> 4;

  assert(lower_nibble < 16);
  assert(upper_nibble < 16);

  unsigned int result = 0;

  result |= (1 << upper_nibble);
  result |= (1 << (lower_nibble + 16));
  return result;
}
Realz Slaw
  • 3,138
  • 1
  • 24
  • 38