hash table!

This is a discussion on hash table! within the C Programming forums, part of the General Programming Boards category; where can i find a good and clean example of hash table? Thank you!...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    hash table!

    where can i find a good and clean example of hash table?

    Thank you!

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    how whould you recomend creating a hash table ia was thinking of something like this:
    i have a struct
    Code:
    typedef struct hash
    {
        int inf;
        struct *hash;
    } hash;
    and i initialize hash a[100];
    i generate the hash key by doing smnthing like %100 and if it conflicts i create a simple linked list.

    is this a good ideea? or there is someway better of aproaching it?

    thank you!

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    You might want to consider a structure more like this:
    Code:
    struct hash
    {
      int inf;
      struct hash *next;
    };
    And then create your table like this: struct hash *a[100];

    That way you only have to deal with one struct which should simplify your code some.

    That's the way I've seen it done and done it myself. Be aware that even if there are no conflicts (correct jargon: collisions) you'll still have a simple linked list at the array index that corresponds with your hash key. It will just contain one node (i.e. a[key]->next should equal NULL if there's no collisions and a[key] should equal NULL if that hash key never came up in your data set). Whatever data you're storing in your hash table will go into the struct's inf member.
    Last edited by itsme86; 04-10-2006 at 11:12 AM.
    If you understand what you're doing, you're not learning anything.

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, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21