Thread: Hash Tables

  1. #1
    Registered User
    Join Date
    Oct 2007

    Hash Tables

    I'm currently in a data structures course at school. We've had to build a word counting program, and at the moment.. I'm completely stuck. For some reason, I get a struct that doesn't seem to malloc. If someone could take a quick peek, or have any information that was wonderful.

    The files are clean. The program interface has to stay the same. The table ADT is what I've been working on.

    I appreciate any help I can get. Thanks.

  2. #2
    Registered User
    Join Date
    Oct 2001
    CFLAGS      =	-Wall -Werror -ansi -pedantic
    Table *tableCreate(int SIZE, int (*stringhash) (void *), int (*stringequals) (void *, void*))
    Table *tableCreate(int Size, int stringhash (void *), int stringequals (void *, void*));
    Last edited by robwhit; 10-28-2007 at 03:17 AM.

  3. #3
    Registered User
    Join Date
    Oct 2007


    What seems to be my biggest issue is, say in my tableGetEntry function...

    InfoType *e;
    unsigned int hashvalue, index;
    hashvalue = hash(table_ptr,word);
    index = indexFor(table_ptr->length,hashvalue);
    e = table_ptr->table[index];
    while (NULL != e)
    		if ((hashvalue == e->hsh) && (table_ptr->stringequals(word, e->word))) return e->count;
    		e = e->next;
    return NULL;
    If I printf my address for InfoType *e, it comes back as 0 or (nil). No information seems to be being saved there.

    robwhit, I change that function, and still that same problem.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    One of the problems seems to be that your table entries contain pointers to data OUTSIDE the table entry itself. If that memory location gets re-used, then all your pointers to that external data change as well.

    Try maintaining local copies of any user data.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Iterable hash tables
    By OnionKnight in forum Tech Board
    Replies: 5
    Last Post: 07-21-2008, 02:02 AM
  2. developing hash tables in the C Programming language
    By w108dab in forum C Programming
    Replies: 1
    Last Post: 05-20-2008, 11:20 AM
  3. need help with hash tables with direct chaining
    By agentsmith in forum C Programming
    Replies: 4
    Last Post: 01-05-2008, 04:19 AM
  4. Group Project Help/Volunteer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2007, 11:36 PM
  5. Problems with Hash Tables
    By Zildjian in forum C Programming
    Replies: 6
    Last Post: 11-06-2003, 08:53 PM