librnr/hash.c
hash_t *hash_table_init(hash_t *hash, hashcount_t minsize, hashcount_t maxsize,
                        hash_comp_t compfun, hash_fun_t hashfun,
                        hnode_data_free_t freedatafun,
                        hnode_t **table, hashcount_t nchains)
{
  LOGDIAG4CALL(_TPTR(hash), _TULONG(minsize), _TULONG(maxsize),
      _TPTR(compfun), _TPTR(hashfun), _TPTR(freedatafun),
      _TPTR(table), _TULONG(nchains));

  // Step 1
  if(hash_val_t_bit == 0)
  {
    compute_bits();
  }

  assert(is_power_of_two(nchains));

  init_hash_sizes(hash, minsize, maxsize);

  // Step 2
  hash->table         = table;
  hash->nchains       = nchains;
  hash->mask          = compute_mask(nchains);  // Step 4
  hash->count         = 0;
  hash->compare       = compfun ? compfun : hash_comp_default;
  hash->hash          = hashfun ? hashfun : hash_fun_default;
  hash->freenodedata  = freedatafun;
  hash->dynamic       = false;    // Step 3

  clear_table(hash);    // Step 5

  if( hash_self_verify )
  {
    assert (hash_table_verify(hash));
  }

  LOGDIAG4("min=%lu, max=%lu, high=%lu, low=%lu, nchains=%lu, mask=0x%lx\n",
      hash->minsize, hash->maxsize, hash->highmark,
      hash->lowmark, hash->nchains, hash->mask);

  return hash;
}
/*!
 * \brief Initialize a user supplied hash table.
 * 
 * The user also supplies a table of chains which is assigned to the hash
 * table . The table is static---it will not grow or shrink.
 *
 * \par Notes &amp; Steps:
 * \b 1.
 *    Initialize hashing.\n
 * \b 2.
 *    Assign hash chains. The user supplied array of pointers hopefully
 *    contains nchains nodes.\n
 * \b 3.
 *    Fixed size.
 * \b 4.
 *    We must dynamically compute the mask from the given power of two table
 *    size. \n
 * \b 5.
 *    The user supplied table can't be assumed to contain null pointers,
 *    so we reset it here.
 *
 * \warning All data in destination hash table is overwritten.
 *
 * \sa hash_table_create()
 *
 * \param hash        The destination hash table.
 * \param minsize     Minimum and initial number of hash entries that will be
 *                    supported.
 * \param maxsize     Maximum number of hash entries that will be supported.
 * \param compfun     Hash key comparator function. NULL will use the default
 *                    strcmp() wrapper.
 * \param hashfun     Hashing function. NULL will used the default string
 *                    hashing function.
 * \param freedatafun User key and data deallocator function. NULL will cause
 *                    no user key or data to be deleted.
 * \param table       The actual hash chain table to attach.
 * \param nchains     Number of nodes in hash chain.
 *
 * \return Hash table.
 *
 * \exception "Bad Parameter" nchain not a power of 2.
 * \exception "Verification Failed" Only if \ref hash_self_verify enabled.
 */
\brief Initialize a user supplied hash table.

The user also supplies a table of chains which is assigned to the hash
table . The table is static---it will not grow or shrink.

\par Notes & Steps:
\b 1.
Initialize hashing.\n
\b 2.
Assign hash chains. The user supplied array of pointers hopefully
contains nchains nodes.\n
\b 3.
Fixed size.
\b 4.
We must dynamically compute the mask from the given power of two table
size. \n
\b 5.
The user supplied table can't be assumed to contain null pointers,
so we reset it here.

\warning All data in destination hash table is overwritten.



\param hash        The destination hash table.
\param minsize     Minimum and initial number of hash entries that will be
supported.
\param maxsize     Maximum number of hash entries that will be supported.
\param compfun     Hash key comparator function. NULL will use the default
strcmp() wrapper.
\param hashfun     Hashing function. NULL will used the default string
hashing function.
\param freedatafun User key and data deallocator function. NULL will cause
no user key or data to be deleted.
\param table       The actual hash chain table to attach.
\param nchains     Number of nodes in hash chain.

\return Hash table.

\exception "Bad Parameter" nchain not a power of 2.
\exception "Verification Failed" Only if \ref hash_self_verify enabled.
\ brief Initialize a user supplied hash table . The user also supplies a table of chains which is assigned to the hash table . The table is static --- it will not grow or shrink . \ par Notes & Steps : \ b 1 . Initialize hashing . \ n \ b 2 . Assign hash chains . The user supplied array of pointers hopefully contains nchains nodes . \ n \ b 3 . Fixed size . \ b 4 . We must dynamically compute the mask from the given power of two table size . \ n \ b 5 . The user supplied table can ' t be assumed to contain null pointers so we reset it here . \ warning All data in destination hash table is overwritten . \ param hash The destination hash table . \ param minsize Minimum and initial number of hash entries that will be supported . \ param maxsize Maximum number of hash entries that will be supported . \ param compfun Hash key comparator function . NULL will use the default strcmp () wrapper . \ param hashfun Hashing function . NULL will used the default string hashing function . \ param freedatafun User key and data deallocator function . NULL will cause no user key or data to be deleted . \ param table The actual hash chain table to attach . \ param nchains Number of nodes in hash chain . \ return Hash table . \ exception " Bad Parameter " nchain not a power of 2 . \ exception " Verification Failed " Only if \ ref hash_self_verify enabled .
hash_t *hash_table_init(hash_t *hash, hashcount_t minsize, hashcount_t maxsize,
                        hash_comp_t compfun, hash_fun_t hashfun,
                        hnode_data_free_t freedatafun,
                        hnode_t **table, hashcount_t nchains)
{
  LOGDIAG4CALL(_TPTR(hash), _TULONG(minsize), _TULONG(maxsize),
      _TPTR(compfun), _TPTR(hashfun), _TPTR(freedatafun),
      _TPTR(table), _TULONG(nchains));
  if(hash_val_t_bit == 0)
  {
    compute_bits();
  }
  assert(is_power_of_two(nchains));
  init_hash_sizes(hash, minsize, maxsize);
  hash->table         = table;
  hash->nchains       = nchains;
  hash->mask          = compute_mask(nchains);  
  hash->count         = 0;
  hash->compare       = compfun ? compfun : hash_comp_default;
  hash->hash          = hashfun ? hashfun : hash_fun_default;
  hash->freenodedata  = freedatafun;
  hash->dynamic       = false;    
  clear_table(hash);    
  if( hash_self_verify )
  {
    assert (hash_table_verify(hash));
  }
  LOGDIAG4("min=%lu, max=%lu, high=%lu, low=%lu, nchains=%lu, mask=0x%lx\n",
      hash->minsize, hash->maxsize, hash->highmark,
      hash->lowmark, hash->nchains, hash->mask);
  return hash;
}
hash_t * hash_table_init ( hash_t * hash , hashcount_t minsize , hashcount_t maxsize , hash_comp_t compfun , hash_fun_t hashfun , hnode_data_free_t freedatafun , hnode_t * * table , hashcount_t nchains ) { LOGDIAG4CALL ( _TPTR ( hash ) , _TULONG ( minsize ) , _TULONG ( maxsize ) , _TPTR ( compfun ) , _TPTR ( hashfun ) , _TPTR ( freedatafun ) , _TPTR ( table ) , _TULONG ( nchains ) ) ; if ( hash_val_t_bit == 0 ) { compute_bits ( ) ; } assert ( is_power_of_two ( nchains ) ) ; init_hash_sizes ( hash , minsize , maxsize ) ; hash -> table = table ; hash -> nchains = nchains ; hash -> mask = compute_mask ( nchains ) ; hash -> count = 0 ; hash -> compare = compfun ? compfun : hash_comp_default ; hash -> hash = hashfun ? hashfun : hash_fun_default ; hash -> freenodedata = freedatafun ; hash -> dynamic = false ; clear_table ( hash ) ; if ( hash_self_verify ) { assert ( hash_table_verify ( hash ) ) ; } LOGDIAG4 ( " \n " , hash -> minsize , hash -> maxsize , hash -> highmark , hash -> lowmark , hash -> nchains , hash -> mask ) ; return hash ; }
\brief Initialize a user supplied hash table.
\ brief Initialize a user supplied hash table .
// Step 1 // Step 2 // Step 4 // Step 3 // Step 5