Thread: hash table explanation

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    75

    hash table explanation

    Hi , do you guys know any good links or tutorials on hash tables since our proffessor didnt do a good job explaining that concept and I have this program to do

    http://k4shif.netfirms.com/program4/prog4.html

    thanks

  2. #2
    root
    Join Date
    Sep 2003
    Posts
    232
    >our proffessor didnt do a good job explaining that concept
    A hash table is basically an array. That's not interesting except for the hash function. The hash function doles out numbers that match indexes of the array so that (ideally) each item you want to put into the array can only be hashed into a single unique index. In other words, this is a hash table:
    Code:
    int lettercount[27];
    
    int hash(char c) { /* Assuming ASCII, deal */
            return c - 'a'; /* Lower case only */
    }
    
    int main ( ) {
            ...
            while ((ch = cin.get()) != EOF)
                    lettercount[hash(ch)]++;
    }
    Each character from a to z is hashed to each array index from 0 to 26. That's what a hash table is, a way to take something that isn't an array index and make it into one so that you can access an array quickly and easily.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dictionary in C# to hash table in C?
    By dinoman in forum C Programming
    Replies: 2
    Last Post: 04-12-2009, 09:23 PM
  2. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  3. Group Project Help/Volunteer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2007, 11:36 PM
  4. Hash table creation and insertion
    By tgshah in forum C Programming
    Replies: 1
    Last Post: 01-23-2006, 07:54 PM
  5. Not sure on hash table memory allocations
    By Thumper333 in forum C Programming
    Replies: 3
    Last Post: 09-27-2004, 09:00 PM