title: Does a perfect hash function guarantee no collisions?
body: <p>I have been reading and learning hashing and hashtables and experemented with some code(I am still very new to this so I might say something wrong that I missunderstood). I came to the issue for perfect hash functions. Provided that I have my own custom type that somehow has a perfect hash function:</p>
  
  <pre><code>class Foo
  {
      private int data;
  
      override int GetHashCode()
      {
          return data.GetHashCode();
      }
  }
  </code></pre>
  
  <p>An <code>int</code>'s hash code is the <code>int</code> itself so I have a perfect hash function, right? But when we use the hashing function to map the objects to a hashtable by the simple formula:</p>
  
  <pre><code>index = foo.GetHashCode() % hashtable.Length
  </code></pre>
  
  <p>we get a variable index that depends on also how many elements we have in the hashtable. If the hashtable's size was int.MaxValue only then we will have a perfect hash function. For example lets say that we have a hashtable with size of 2. And if we hash for example the numbers 1 and 3 we get</p>
  
  <pre><code>1 % 2 = 1
  3 % 2 = 1
  </code></pre>
  
  <p>A collision! Have I understood anything wrong about hashing and hashtables? It comes out that a perfect hash function is not perfect.</p>