Thread: Hash tables / hash maps

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    91

    Hash tables / hash maps

    Hi I am having trouble wrapping my head around on how to empty my buckets.

    Code:
    struct hashLink {
    	KeyT key; /*the key is what you use to look up a hashLink*/
    	ValueT value; /*the value stored with the hashLink, an int*/
    	struct hashLink * next; /* linked list nodes*/
    };
    typedef struct hashLink hashLink;
    
    struct hashMap {
        hashLink ** table; /*array of pointers to hashLinks*/
        int tableSize; /* number of buckets in table*/
        int count; /*number of hashLinks in table*/
    };
    
    
    /* Other functions to insert, remove, the initialize the hash, etc. */
    
    int cleanBuckets(struct hashMap *hasht) {
        
         /* what I'm trying to do here is return the amount of empty or clean buckets in the table, where the buckets have no links */
    }
    Thanks in advance.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by dlwlsdn View Post
    Hi I am having trouble wrapping my head around on how to empty my buckets.
    What's wrong with just iterating thru the array? What are the buckets -- linked lists?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    91
    Nevermind, I got it

    Thanks for responding though. Seems like coffee can do the trick sometimes lol.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm not surprised that you found the answer - most folk do:

    1) Grasp the top rim of the bucket, with one hand.

    2) With the other hand supporting the bottom rim, lift and invert the bucket.

    Brilliant advice, given away for free - what a forum!

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