librnr/hash.c
hnode_t *hash_scan_next(hscan_t *scan)
{
  hnode_t     *next     = scan->next;    // Step 1
  hash_t      *hash     = scan->hash;
  hash_val_t   chain    = scan->chain + 1;
  hash_val_t   nchains  = hash->nchains;

  assert(hash_val_t_bit != 0);  // Step 2

  // Step 3
  if(next)
  {
    // Step 4
    if(next->next)
    {
      scan->next = next->next;
    }
    else
    {
      // Step 5
      while(chain < nchains && hash->table[chain] == 0)
      {
        chain++;
      }
      // Step 6
      if (chain < nchains)
      {
        scan->chain = chain;
        scan->next = hash->table[chain];
      }
      else
      {
        scan->next = NULL;
      }
    }
  }
  return next;
}
/*!
 * \brief Retrieve the next node from the hash table.
 *
 * The scanner (iterator) updates the pointer for the next invocation of
 * hash_scan_next(). 
 *
 * \par Notes &amp; Steps:
 * \b 1.
 *    Remember the next pointer in a temporary value so that it can be
 *    returned.\n
 * \b 2.
 *    This assertion essentially checks whether the module has been properly
 *    initialized. The first point of interaction with the module should be
 *    either hash_table_create() or hash_init(), both of which set
 *    hash_val_t_bit to a non zero value.\n
 * \b 3.
 *    If the next pointer we are returning is not NULL, then the user is
 *    allowed to call hash_scan_next() again. We prepare the new next pointer
 *    for that call right now. That way the user is allowed to delete the node
 *    we are about to return, since we will no longer be needing it to locate
 *    the next node.\n
 * \b 4.
 *    If there is a next node in the chain (next->next), then that becomes the
 *    new next node, otherwise ...\n
 * \b 5.
 *    We have exhausted the current chain, and must locate the next subsequent
 *    non-empty chain in the table.\n
 * \b 6.
 *    If a non-empty chain is found, the first element of that chain becomes
 *    the new next node. Otherwise there is no new next node and we set the
 *    pointer to NULL so that the next time hash_scan_next() is called, a null
 *    pointer shall be immediately returned.\n
 *
 * \return Returns next node on success, NULL if no more nodes.
 *
 * \exception "Not Initialzed"  Hashing not initialized.
 */
\brief Retrieve the next node from the hash table.
The scanner (iterator) updates the pointer for the next invocation of
hash_scan_next().

\par Notes & Steps:
\b 1.
Remember the next pointer in a temporary value so that it can be
returned.\n
\b 2.
This assertion essentially checks whether the module has been properly
initialized. The first point of interaction with the module should be
either hash_table_create() or hash_init(), both of which set
hash_val_t_bit to a non zero value.\n
\b 3.
If the next pointer we are returning is not NULL, then the user is
allowed to call hash_scan_next() again. We prepare the new next pointer
for that call right now. That way the user is allowed to delete the node
we are about to return, since we will no longer be needing it to locate
the next node.\n
\b 4.
If there is a next node in the chain (next->next), then that becomes the
new next node, otherwise ...\n
\b 5.
We have exhausted the current chain, and must locate the next subsequent
non-empty chain in the table.\n
\b 6.
If a non-empty chain is found, the first element of that chain becomes
the new next node. Otherwise there is no new next node and we set the
pointer to NULL so that the next time hash_scan_next() is called, a null
pointer shall be immediately returned.\n

\return Returns next node on success, NULL if no more nodes.

\exception "Not Initialzed"  Hashing not initialized.
\ brief Retrieve the next node from the hash table . The scanner ( iterator ) updates the pointer for the next invocation of hash_scan_next () . \ par Notes & Steps : \ b 1 . Remember the next pointer in a temporary value so that it can be returned . \ n \ b 2 . This assertion essentially checks whether the module has been properly initialized . The first point of interaction with the module should be either hash_table_create () or hash_init () both of which set hash_val_t_bit to a non zero value . \ n \ b 3 . If the next pointer we are returning is not NULL then the user is allowed to call hash_scan_next () again . We prepare the new next pointer for that call right now . That way the user is allowed to delete the node we are about to return since we will no longer be needing it to locate the next node . \ n \ b 4 . If there is a next node in the chain ( next - > next ) then that becomes the new next node otherwise ... \ n \ b 5 . We have exhausted the current chain and must locate the next subsequent non - empty chain in the table . \ n \ b 6 . If a non - empty chain is found the first element of that chain becomes the new next node . Otherwise there is no new next node and we set the pointer to NULL so that the next time hash_scan_next () is called a null pointer shall be immediately returned . \ n \ return Returns next node on success NULL if no more nodes . \ exception " Not Initialzed " Hashing not initialized .
hnode_t *hash_scan_next(hscan_t *scan)
{
  hnode_t     *next     = scan->next;    
  hash_t      *hash     = scan->hash;
  hash_val_t   chain    = scan->chain + 1;
  hash_val_t   nchains  = hash->nchains;
  assert(hash_val_t_bit != 0);  
  if(next)
  {
    if(next->next)
    {
      scan->next = next->next;
    }
    else
    {
      while(chain < nchains && hash->table[chain] == 0)
      {
        chain++;
      }
      if (chain < nchains)
      {
        scan->chain = chain;
        scan->next = hash->table[chain];
      }
      else
      {
        scan->next = NULL;
      }
    }
  }
  return next;
}
hnode_t * hash_scan_next ( hscan_t * scan ) { hnode_t * next = scan -> next ; hash_t * hash = scan -> hash ; hash_val_t chain = scan -> chain + 1 ; hash_val_t nchains = hash -> nchains ; assert ( hash_val_t_bit != 0 ) ; if ( next ) { if ( next -> next ) { scan -> next = next -> next ; } else { while ( chain < nchains && hash -> table [ chain ] == 0 ) { chain ++ ; } if ( chain < nchains ) { scan -> chain = chain ; scan -> next = hash -> table [ chain ] ; } else { scan -> next = NULL ; } } } return next ; }
\brief Retrieve the next node from the hash table.
\ brief Retrieve the next node from the hash table .
// Step 1 // Step 2 // Step 3 // Step 4 // Step 5 // Step 6