Thread: Insert Items in Hash Table Container.

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I see no reason for it to be public
    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.

  2. #17
    Registered User
    Join Date
    May 2005
    Posts
    24
    you could pass the hash generator as a template parameter (that would default to some predefined object).

  3. #18
    Registered User
    Join Date
    Mar 2005
    Posts
    77
    I also created an method VALUETYPE getItem( const string& key ) const; inside the public

    However, when I tried to compile it the HastTableTest.cpp, it shows I have 2 errors
    Here is my code from the method getItem
    Code:
    template <typename KEYTYPE, typename VALUETYPE>
    VALUETYPE HashTable<KEYTYPE,VALUETYPE>::getItem( const string& key ) const {
    
        VALUETYPE 	value;
    
        return value;
    }
    Also for the method getIndex, Do you think it should return res instead of returning *key % 20?
    Last edited by joenching; 05-02-2005 at 01:29 PM.

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You need to use the same kind of code to get elements out as you use to store them

    Code:
    template <typename KEYTYPE, typename VALUETYPE>
    VALUETYPE HashTable<KEYTYPE,VALUETYPE>::getItem( const string& key ) const {
        int position = myHashFunction( key );  // compute a position
        // now do domething with hashTable[position]
        // bearing in mind that there could be any number of entries at this hash position
        // see your example output.
    }
    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. 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. Linked List Queue Implementation help
    By Kenogu Labz in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2005, 10:14 AM