4.4 Lookup

To look up an entry in a hash table is almost trivial. It is listed in listing 5.


Listing 5:hashlookup
 
1const char *HashTable_lookup(struct HashTable *_pht, const char *key) 
2{ 
3  int hashvalue = h(key, MAX_ENTRIES); 
4  struct _HashTable *pht = (struct _HashTable *)_pht; 
5  const char *result = NULL; 
6 
7  if (pht->table[hashvalue].flags & HASHENTRY_INUSE) 
8  { 
9    result = pht->table[hashtable].value; 
10  } 
11  return result; 
12}

Again, this code is almost correct, but not quite.