librnr/hash.c
hnode_t *hash_lookup(hash_t *hash, const void *key)
{
  hash_val_t hkey, chain;
  hnode_t *nptr;

  hkey = hash->hash(key);       // Step 1
  chain = hkey & hash->mask;    // Step 2

  // Step 3
  for(nptr = hash->table[chain]; nptr; nptr = nptr->next)
  {
    if(nptr->hkey == hkey && hash->compare(nptr->key, key) == 0)
    {
      return nptr;
    }
  }

  return NULL;
}
/*!
 * \brief Find a node in the hash table and return a pointer to it.
 *
 * \par Notes &amp; Steps:
 * \b 1.
 *    We hash the key and keep the entire hash value. As an optimization, when
 *    we descend down the chain, we can compare hash values first and only if
 *    hash values match do we perform a full key comparison.\n
 * \b 2.
 *    To locate the chain from among 2^N chains, we look at the lower N bits of
 *    the hash value by anding them with the current mask.\n
 * \b 3.
 *    Looping through the chain, we compare the stored hash value inside each
 *    node against our computed hash. If they match, then we do a full
 *    comparison between the unhashed keys. If these match, we have located the
 *    entry.
 *
 *
 * \param hash  Hash table.
 * \param key   Hash key.
 *
 * \return Returns node with key on success, NULL if node not found.
 */
\brief Find a node in the hash table and return a pointer to it.
\par Notes & Steps:
\b 1.
We hash the key and keep the entire hash value. As an optimization, when
we descend down the chain, we can compare hash values first and only if
hash values match do we perform a full key comparison.\n
\b 2.
To locate the chain from among 2^N chains, we look at the lower N bits of
the hash value by anding them with the current mask.\n
\b 3.
Looping through the chain, we compare the stored hash value inside each
node against our computed hash. If they match, then we do a full
comparison between the unhashed keys. If these match, we have located the
entry.

\param hash  Hash table.
\param key   Hash key.

\return Returns node with key on success, NULL if node not found.
\ brief Find a node in the hash table and return a pointer to it . \ par Notes & Steps : \ b 1 . We hash the key and keep the entire hash value . As an optimization when we descend down the chain we can compare hash values first and only if hash values match do we perform a full key comparison . \ n \ b 2 . To locate the chain from among 2^N chains we look at the lower N bits of the hash value by anding them with the current mask . \ n \ b 3 . Looping through the chain we compare the stored hash value inside each node against our computed hash . If they match then we do a full comparison between the unhashed keys . If these match we have located the entry . \ param hash Hash table . \ param key Hash key . \ return Returns node with key on success NULL if node not found .
hnode_t *hash_lookup(hash_t *hash, const void *key)
{
  hash_val_t hkey, chain;
  hnode_t *nptr;
  hkey = hash->hash(key);       
  chain = hkey & hash->mask;    
  for(nptr = hash->table[chain]; nptr; nptr = nptr->next)
  {
    if(nptr->hkey == hkey && hash->compare(nptr->key, key) == 0)
    {
      return nptr;
    }
  }
  return NULL;
}
hnode_t * hash_lookup ( hash_t * hash , const void * key ) { hash_val_t hkey , chain ; hnode_t * nptr ; hkey = hash -> hash ( key ) ; chain = hkey & hash -> mask ; for ( nptr = hash -> table [ chain ] ; nptr ; nptr = nptr -> next ) { if ( nptr -> hkey == hkey && hash -> compare ( nptr -> key , key ) == 0 ) { return nptr ; } } return NULL ; }
\brief Find a node in the hash table and return a pointer to it.
\ brief Find a node in the hash table and return a pointer to it .
// Step 1 // Step 2 // Step 3