yaroz_vn posted:
Alrighty.
I don't know how much you know about Hashtables, but here is a basic intro.
Hashtables are also called "Dictionaries". They have 2 pieces needed for storage. A Key which has to be unique, and a Value which is the data you want to reference by the Key.
A hashtable works by performing a "hashing" function on the "Key" which gives an instant Index for the array. The Array is fairly large to accommodate a lot of values initially. The actual size varies on declaration and implementation. You trade off space for speed.
they normally do something like hash(name) % arraysize to produce a value between 0 and (the size of the array - 1)
This allows almost instant access to your Value since hash(name) will ALWAYS produce the same number. That's the point of the hash function.
So.. if you use the "alt name" as the Key (since it should be the unique name anyway) then you can QUICKLY use that name to determine the VALUE associated with it (the Non-unique MAIN identity).
So you'd basically have hashtable['altname'] = 'mainname'
Then when you want to read the main name, you'd just again reference hashtable['altname'] and it would give you the mainname directly. No "Searching" through arrays or other collections. Even a binary search takes time AND the names have to be sorted first.