Hash table - problem

This is a discussion on Hash table - problem within the C++ Programming forums, part of the General Programming Boards category; This is my first attempt at a hash table data structure. My problem is how can i change the stuct ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123

    Hash table - problem

    This is my first attempt at a hash table data structure. My problem is how can i change the stuct Entry_t for the class Hash_map so that Entry wouldn't be invalidated type. Also, i get this error "error C4430: missing type specifier - int assumed" for my function pointer declaration...


    Code:
    typedef template< class Map>
    class Hash_Map
    { 
    
    
     private :
      typedef struct Entry_t
    {
      Map * Object;
      Entry_t * next;
      string * Key;
      int position;
    }Entry * Primary[], * Seconadary[];
    
      
      Entry *  make_node(std::string, Map * map  );
    
      size_t Num;
      size_t secondary_size;
      unsigned int (*Hash_function) (const * char, int );
      
      public:
      Hash_Map( Entry & P , size_t &  N );
      Hash_Map( Hash_Map & Map_secondary);
      // the default SuperFastHash comes from the included header file 
      Hash_Map( int & num, unsigned int(*Hash_funct)(const * char, int) = SuperFastHash); 
      ~Hash_Map();
      int   insert(std::string key, Map & map);
    
      int   deletion(std::string key);
    
      bool  isFull();
     
      Map * find(std::string key);
    
      int   Secondaryinsert(std::string key, Map & map);
    
      Swap_Hash(int leftoff)
      
    };
    
    #endif
    Attached Files Attached Files

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, I haven't reviewed the whole thing thoroughly, and I haven't compiled it, but there were a couple of things I noticed:

    - Line #27 of Hash_file.cc has an incomplete statement and no semicolen.
    - The implementation functions in Hash_file.cc have to be templated, eg:

    Code:
    template< class Map>
    Hash_Map<Map>::Hash_Map( const Hash_Map & Map_secondary)
    {
    // ...
    }
    - Drop the typedef before the Hash_Map class declaration.
    - If you're going to pass references to the functions, make them const
    - You can't assign your member variable to the local variable "Array", as it will be destroyed when the function completes.

    Code:
    typedef template< class Map>
    Entry * Hash_Map::make_node(std::string key, Map * map  )
    {
      Entry * Cur, 
    
      Cur = new Entry; 
    
      Cur->Object = map;
    
      Cur->Key = &key;
    
      Cur->next = NULL;
    
      return(Cur);
    
    }
    You're basically doing the same thing here. First of all, "key" is just a temporary, and second you really shouldn't be forming a pointer to the string the user passes in *anyway*. Just declare the member as a plain std::string.

    - Your insert function looks confused. First of all, you don't need to iterate through the array. That is, after all, the whole purpose of using a hash function! Next, you're just overwriting the current node. You just need to grab the node at Primary[h], iterate to the end, and add the new node.
    - Your delete function is equally broken. Do similar to the above method, but when/if you find a matching node, you'll need to point it's predecessor to the next node, and then delete the current one, if that makes sense.

    Sorry, but that's all I've got time for right now. Fix those errors and you'll be a little closer to a correct solution, at least.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    thanks for the help, I fixed most of the errors, but then I get a linker error " [Linker error] undefined reference to `Hash_Map<int>::Hash_Map(int)' " and the other members... when i made a Main test file

    Code:
    #include <iostream>
    using namespace std;
    
    #include "Hash_file.h"
    
    
    
    int main(void)
    {
    	Hash_Map<int> Numbers(3);
        Numbers.insert("one", 1);
    	Numbers.insert("two", 2 );
    	Numbers.insert("Three",3);
    
    	cout<<LNumbers.find("one");
    
    
    	cin.get();
    	return 0;
    }
    Attached Files Attached Files
    Last edited by Darkinyuasha1; 07-20-2009 at 04:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to make a hash table......trouble w/ memory?
    By cuizy in forum C Programming
    Replies: 3
    Last Post: 05-11-2009, 04:47 PM
  2. Hash Table outputting incorrect number
    By Paul Skinner in forum C Programming
    Replies: 4
    Last Post: 11-20-2008, 05:19 AM
  3. Hash Table implementation
    By supaben34 in forum C++ Programming
    Replies: 6
    Last Post: 09-26-2003, 12:48 PM
  4. Problem with Hash Table Linear Probing
    By kirby1024 in forum C Programming
    Replies: 5
    Last Post: 10-23-2002, 06:03 AM
  5. help with creating a hash table
    By newbie40 in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2002, 07:31 PM

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