4

When are hash functions orthogonal to each other?

And can you provide an example in Java of two hash functions that are orthogonal to each other?

hopper
  • 13,060
  • 7
  • 49
  • 53
Marcus
  • 1,222
  • 2
  • 13
  • 22
  • 1
    I just searched for the term, followed the first link, and there was a definition... – Jon Skeet Feb 11 '14 at 18:00
  • 1
    Hey Jon, the Google feed of question is very fast. This question is already top 4 on Google: hash functions orthogonal. However, since I changed the question, the Google result isn't up-to-date any more. Nevertheless this proves that the question wasn't asked on stackoverflow before. ;) – Marcus Feb 11 '14 at 18:16
  • 1
    Did I say that the link was Stack Overflow? Not *everything* has to be defined on SO. I generally think that if a question can be answered by putting in a simple (and obvious) query and following the first link, it's not worth asking the question. – Jon Skeet Feb 11 '14 at 18:18
  • Well, I didn't really found any resource in the internet describing in simple and clear terms what orthogonal hash functions are. I'm actually still not sure what they really are. That's why I asked. – Marcus Feb 11 '14 at 18:19
  • 2
    So you did actually look? It would be helpful if you'd state what you found *and, most importantly* what confused you about the description. Otherwise you'll find people just quoting the same things to you, which isn't helpful. – Jon Skeet Feb 11 '14 at 18:22
  • Well, there are really not much resources out there, but some stackoverflow crawlers: http://queforum.com/programming-languages-basics/640632-java-what-orthogonal-hash-functions.html – Marcus Feb 11 '14 at 18:24
  • 1
    No, there's a perfectly good resource. http://www.aaai.org/ocs/index.php/ICAPS/ICAPS10/paper/download/1439/1529 – Jon Skeet Feb 11 '14 at 18:25

2 Answers2

2

From (a Google search result paper)

(Orthogonal Hash Functions) Two hash functions h1 and h2 are orthogonal, if for all states s, s' ∈ S with h1 (s) = h1 (s') and h2 (s) = h2 (s') we have s = s'.

S. Edelkamp, Perfect Hashing for State Space Exploration on the GPU.

In English, if any two given values passed to two different orthogonal hash functions result in the same outputs, those inputs must have been the same value.

Example:

Let h and g be hash functions.
Let b be a currently unknown value.
h(0) = h(b) = 5
g(0) = g(b) = 4
if h and g are orthogonal, b MUST equal 0.

Thus for any values given to h that result in a unique result,
If those same values are given to g, they must also result in a unique result,
  IF they are orthogonal hash functions.

Pseudocode:

// Assume no wraparound will ever occur due to overflow.
HashFunc h = x -> x + 1;
HashFunc g = y -> y + 2;
h(0) = 1 // No other input value results in --> 1
g(0) = 2 // No other input value results in --> 2
// These must have been orthogonal hash functions.

// Now for some non-orthogonal hash functions:
// Let the domain be integers only.
HashFunc j = x -> ceil(abs(x / 2));
HashFunc k = x -> ceil(sqrt(x));
j(0) = 0 // Unique result
k(0) = 0 // Unique result
j(1) = j(2) = 1
k(1) = 1 != k(2) = 2 
// k(1) results in a unique value, but it isn't unique for j.
// These cannot be orthogonal hash functions.
BlackVegetable
  • 12,594
  • 8
  • 50
  • 82
  • Instead of "If any two given values passed to two different hash functions" you meant to say "If any two given values passed to two different _orthogonal_ hash functions", I believe... – Floris Feb 11 '14 at 18:28
  • @Floris Nice catch. I'll fix that. Sorry for the confusion. – BlackVegetable Feb 11 '14 at 18:31
  • This is using Java 8-ish notation (which will be out in a month or so from the time of this posting.) – BlackVegetable Feb 11 '14 at 18:35
2

enter image description here

from http://www.aaai.org/ocs/index.php/ICAPS/ICAPS10/paper/download/1439/1529

Obtained with Google: define "orthogonal hash" (second hit).

Translating:

If you have a "perfect hashing function", then h(s) == h(s') iff s == s'.

If you have "any two hashing functions" for which there are values s, s' that have both

h1(s) == h1(s') and h2(s) == h2(s')

then these functions are called orthogonal if the above is true for s == s'

It's actually quite a tricky concept. If h1 and h2 were both perfect hashing functions, then they would automatically have to be orthogonal according to the above definition (if I understand correctly). But you can have imperfect functions that fit the above definition.

Example: in the state space [0, 9], two functions

h1(int x) return x % 5;

h2(int x) return x % 7;

Would be orthogonal:

x  h1  h2
0   0   0
1   1   1 
2   2   2
3   3   3
4   4   4
5   0   5
6   1   6
7   2   0
8   3   1
9   4   2

In the above, h1(s) = h1(s') for pairs of values s that are either 0 apart or 5 apart. For h1, the distance is either 0 or 7.

The only pairs for which both conditions are true are those where the distance is 0 - so only when s1 == s2. Thus these are orthogonal (although imperfect) hashing functions.

And that, I think, answers both parts of your question.

Floris
  • 45,857
  • 6
  • 70
  • 122