Hash Tables

This is a discussion on Hash Tables within the C Programming forums, part of the General Programming Boards category; I'm currently in a data structures course at school. We've had to build a word counting program, and at the ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    8

    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.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    CFLAGS      =	-Wall -Werror -ansi -pedantic
    Code:
    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
    Posts
    8

    Unhappy

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

    Code:
    	
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 03: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, 07:53 PM

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