08-27-2006 07:21 AM
08-28-2006 08:44 AM - edited 08-28-2006 08:44 AM
Message Edited by DFGray on 08-28-2006 08:47 AM
08-29-2006 10:34 AM
Yeah, 'Search 1D Array' is pretty quick, but on average you'll have to look at 1/2 the array elements before you find the one you're looking for. With hashing, you'll have to perform the hash computation, but can then generally index straight to the corresponding element. In the event of the occasional hash "collision" (two different input strings map to the same numeric hash value), you'll look at another element or two.
The tradeoff is to compare the time needed to index and compare many array elements vs. the time needed to compute a hash value (and the non-negligible difficulty of implementing the additional code). Hashing mainly becomes attractive for large collections where lookup time needs to be optimized.
I tend to think of hashing as applying primarily to strings, but with a little creativity it could also be applied to other chunks of bytes such as custom cluster datatypes. Hmmmm....
-Kevin P.
08-30-2006 08:23 AM
09-01-2006 04:24 PM