Thread: HashTable help?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #34
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so I should add it to the front of the list and , in other words add to temp?

    Code:
    boolean HashTableInsert(HashTable *this, const char* key, const char* value)
    {
      list_t *temp;
    
      int_u4 hashval = StringHash(key) % this->length;
    
      /* Does item already exist? */
      for (temp = this->table[hashval]; temp != NULL; temp = temp->next){
        if (strcmp(key, temp->key) == 0){
           StringDestruct(temp->value);
           temp->value = StringConstruct(value);
           return false;
        }
      }
      list_t *new_list;
      if ((new_list = malloc(sizeof(list_t))) == NULL)
        outOfMemory_(__LINE__, __FILE__, "struct node creation");
      new_list->key = StringConstruct(key);
      new_list->value = StringConstruct(value);
      new_list->next = NULL;
      temp->next = new_list;
      this->length = this->length + 1;
      return true;
    }
    I am not sure if I missed temp by one slot..
    Last edited by -EquinoX-; 03-29-2008 at 11:13 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hashtable v.s. Dictionary
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-06-2008, 02:09 AM
  2. Missing Entries in Hashtable
    By wuzzo87 in forum C Programming
    Replies: 3
    Last Post: 05-13-2007, 12:46 AM
  3. Replies: 12
    Last Post: 10-22-2006, 08:37 PM
  4. game hashtable
    By disks86 in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2005, 01:42 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM