Advertisement

What's a Hash Table?

Started by May 16, 2000 08:10 AM
2 comments, last by REF_Cracker 24 years, 7 months ago
Just wondering if anyone could tell me what a hash table is and what they are used for?

Check out my project @ www.exitearth.com

I know what a hashtable is. The matter is that i don''t speak english good enough to explain it

But anyway, let''s try!

A hashtable is a kind of array. However, when you want to store a new value, you calculate its index with a formula. Storing you values this way allows you to find them quickly (applying the formula). It''s useful if you want to seek for things you''ve stored.

You can easily find more complete informations about this in an algorithm book.


Advertisement
Thanks,
You can explain more in french if you wish!
I live in Quebec so I will understand you!

Check out my project @ www.exitearth.com

Hash Tables in ''n'' words or less.

A hash table is way to sort data so that retreival can be done in constant time. To get this high speed performance however, you need lots of memory. Normally hash tables use twice as much memory as the data they''re actually storing.

So the hash table itsself is like a big array, and every item you want sorted is ''hashed'' or put into this array at an index that is somehow derived from its address space, or some other key unique to the data. The acutally hashing function is not rocket science, just something that grabs a few bits out of an address. So the hash function derives a psuedo-unique identifier from the data item and then the item is stored in the array at that index.
Since you''ve got way more array spaces than items, this normally works really well, but sometimes 2 data items will derive the same identifier (I said psuedo-unique you know) and then you run into problems where you''re trying to put 2 entries into the same place in an array. There are a couple of remedies for this, most commonly, the array is an array of linked lists, so that any 2 things hashed to the same place can simply be strung out, and all still belong to this same hash address.

Hash tables are for fast sorting when you''ve got memory to spare.

This topic is closed to new replies.

Advertisement