title: How to map string keys to unique integer IDs?
body: <p>I have some data that comes regularily as a dump from a data souce with a string natural key that is long (up to 60 characters) and not relevant to the end user. I am using this key in a url. This makes urls too long and user unfriendly.</p>
  
  <p>I would like to transform the string keys into integers with the following requirements:</p>
  
  <p>The source dataset will change over time.</p>
  
  <p>The ID should be:</p>
  
  <ul>
  <li>non negative integer</li>
  <li>unique and constant even if the set of input keys changes</li>
  <li>preferrably reversible back to key (not a strong requirement)</li>
  </ul>
  
  <p>The database is rebuilt from scratch every time so I can not remember the already assigned IDs and match the new data set to existing IDs and generate sequential IDs for the added keys.</p>
  
  <p>There are currently around 30000 distinct keys and the set is constantly growing.</p>
  
  <p>How to implement a function that will map string keys to integer IDs?</p>
  
  <p>What I have thought about:</p>
  
  <p><code>1.</code> Built-in string.GetHashCode: </p>
  
  <p><code>ID(key) = Math.Abs(key.GetHashCode())</code></p>
  
  <ul>
  <li>is not guaranteed to be unique</li>
  <li>(not reversible)</li>
  </ul>
  
  <p><code>1.1</code> "Re-hashing" the built-in GetHashCode until a unique ID is generated to prevent collisions.</p>
  
  <ul>
  <li>existing IDs may change if something colliding is added to the beginning of the input data set</li>
  </ul>
  
  <p><code>2.</code> a perfect hashing function </p>
  
  <ul>
  <li>I am not sure if this can generate constant IDs if the set of inputs changes</li>
  <li>(not reversible)</li>
  </ul>
  
  <p><code>3.</code> translate to base 36/64/??</p>
  
  <ul>
  <li>does not shorten the long keys enough</li>
  </ul>
  
  <p>What are the other options?</p>