Thread: problem retaining data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124

    problem retaining data

    A few days ago i posted about my hash table template.. i given up on it to make smaller functions which were easier, and it compiled with no problem. The problem I'm having is after testing the program with two elements into the hash table, the third additional element bugs the data structure.

    Code:
    int HashTable_insert( const char * hash_key, void * object, _instant_hash * entry_array)
    {
        
        unsigned int h = SuperFastHash(hash_key, strlen(hash_key)) % entry_array->size;
        
        if(entry_array->table[h] == NULL)
      {  
         struct _node * Cur = (_node *)malloc(sizeof(_node));
         Cur->object = object;
         Cur->key = hash_key;
         entry_array->table[h] = Cur;
         return 0;
      }
      else
      {
        struct _node * it;
    	 
    
    	  while(entry_array->cursor < entry_array->size && entry_array->table[entry_array->cursor] != NULL)
    		  ++entry_array->cursor;
    	  if( entry_array->cursor == entry_array->size)
    		  return 1;
    
    	  struct _node * Cur = (_node *)malloc(sizeof(_node));
          Cur->object = object;
          Cur->key = hash_key;
          entry_array->table[entry_array->cursor] = Cur;
    	  it = entry_array->table[h];
    
    	  while(it->next != NULL)
    		  it = it->next;
    
    	  it->next = entry_array->table[entry_array->cursor];
         return 0;
      }  
      
      return 1;
    }
    Last edited by Darkinyuasha1; 07-21-2009 at 02:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. problem with data in allocated memory
    By supi in forum C Programming
    Replies: 3
    Last Post: 06-09-2008, 02:06 AM
  3. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM
  4. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  5. Replies: 4
    Last Post: 06-14-2005, 05:45 AM