Thread: how do hash tables work?

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    132

    how do hash tables work?

    I'm reading up on hash tables and hashing functions and there's one thing that I don't get. A hashing function takes a key and converts it into a memory address, right? What exactly is a key? Is it the same as an index in an array?

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    A key is the thing you want to use to refer to the piece of data.

    For example, if you are building a hash table of names to phone numbers, and you want to be able to look up the phone number given the name, the names would be the keys.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    132
    ok, so it's not a particular data type?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Nope, it can be any type, as long as it can be hashed.

    That's the purpose of the hashing function - to make the key an int (usually), so you can use it to index an array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with unaligned intrinsics
    By The Wazaa in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2009, 12:36 PM
  2. How do Hash Tables insert?
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 12-09-2002, 02:28 AM
  3. Hash tables
    By PJYelton in forum C++ Programming
    Replies: 0
    Last Post: 11-27-2002, 10:42 AM
  4. Help with beginning hash tables, please.
    By Will in forum C++ Programming
    Replies: 8
    Last Post: 11-17-2002, 09:51 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM