librnr/hash.c
hash_t *hash_table_create(bool_t isdynamic,
                          hashcount_t minsize,
                          hashcount_t maxsize,
                          hash_comp_t compfun,
                          hash_fun_t hashfun,
                          hnode_data_free_t freedatafun)
{
  hash_t *hash;

  LOGDIAG4CALL(_TBOOL(isdynamic), _TULONG(minsize), _TULONG(maxsize),
      _TPTR(compfun), _TPTR(hashfun), _TPTR(freedatafun));

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

  // Step 2
  hash = NEW(hash_t);

  // Step 3
  init_hash_sizes(hash, minsize, maxsize);

  // Step 4
  hash->table = (hnode_t **)new(sizeof(hnode_t *) * hash->minsize);

  // Step 5
  hash->nchains       = minsize;
  hash->mask          = compute_mask(hash->nchains);
  hash->count         = 0;
  hash->compare       = compfun ? compfun : hash_comp_default;
  hash->hash          = hashfun ? hashfun : hash_fun_default;
  hash->freenodedata  = freedatafun;

  // Step 6
  hash->dynamic       = isdynamic;

  // Step 7
  clear_table(hash);

  // Step 8
  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 Create a dynamic hash table.
 *
 * Both the hash table structure and the table itself are dynamically allocated.
 * Furthermore, the table is extendible in that it will automatically grow as
 * its load factor increases beyond a certain threshold.
 *
 * \par Notes &amp; Steps:
 * \b 1.
 *    If the number of bits in the hash_val_t type has not been computed yet,
 *    we do so here, because this is likely to be the first function that the
 *    user calls.\n
 * \b 2.
 *    Allocate hash table.\n
 * \b 3.
 *    Initialize hash table sizes. The minsize should be a power of two.
 *    The maxsize should be >= minsize. Both values will be adjusted. The high
 *    and low marks are always set to be twice the table size and half the
 *    table size respectively. When the number of nodes in the table grows
 *    beyond the high size (beyond load factor 2), it will double in size to
 *    cut the load factor down to about about 1. If the table shrinks down to
 *    or beneath load factor 0.5, it will shrink, bringing the load up to
 *    about 1. However, the table will never shrink beneath minsize even if
 *    it's emptied.\n
 * \b 4.
 *    Allocate the table of hash chains.\n
 * \b 5.
 *    Finish initializing the hash structure and the table.
 * \b 6.
 *    This indicates that the table is dynamically allocated and dynamically
 *    resized on the fly. A table that has this value set to zero is
 *    assumed to be statically allocated and will not be resized.\n
 * \b 7.
 *    The table of chains must be properly reset to all null pointers.
 * \b 8.
 *    Verify table's correctness, if self-verification is true.
 *
 * \param isdynamic   The hash table is [not] automatically grow. If set to
 *                    false, the hash table is initialized t be fixed at 
 *                    minsize and maxsize is ignored.
 * \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.
 *
 * \return Newly created, empty hash table.
 *
 * \exception "Verification Failed" Only if \ref hash_self_verify enabled.
 */
\brief Create a dynamic hash table.
Both the hash table structure and the table itself are dynamically allocated.
Furthermore, the table is extendible in that it will automatically grow as
its load factor increases beyond a certain threshold.

\par Notes & Steps:
\b 1.
If the number of bits in the hash_val_t type has not been computed yet,
we do so here, because this is likely to be the first function that the
user calls.\n
\b 2.
Allocate hash table.\n
\b 3.
Initialize hash table sizes. The minsize should be a power of two.
The maxsize should be >= minsize. Both values will be adjusted. The high
and low marks are always set to be twice the table size and half the
table size respectively. When the number of nodes in the table grows
beyond the high size (beyond load factor 2), it will double in size to
cut the load factor down to about about 1. If the table shrinks down to
or beneath load factor 0.5, it will shrink, bringing the load up to
about 1. However, the table will never shrink beneath minsize even if
it's emptied.\n
\b 4.
Allocate the table of hash chains.\n
\b 5.
Finish initializing the hash structure and the table.
\b 6.
This indicates that the table is dynamically allocated and dynamically
resized on the fly. A table that has this value set to zero is
assumed to be statically allocated and will not be resized.\n
\b 7.
The table of chains must be properly reset to all null pointers.
\b 8.
Verify table's correctness, if self-verification is true.

\param isdynamic   The hash table is [not] automatically grow. If set to
false, the hash table is initialized t be fixed at
minsize and maxsize is ignored.
\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.

\return Newly created, empty hash table.

\exception "Verification Failed" Only if \ref hash_self_verify enabled.
\ brief Create a dynamic hash table . Both the hash table structure and the table itself are dynamically allocated . Furthermore the table is extendible in that it will automatically grow as its load factor increases beyond a certain threshold . \ par Notes & Steps : \ b 1 . If the number of bits in the hash_val_t type has not been computed yet we do so here because this is likely to be the first function that the user calls . \ n \ b 2 . Allocate hash table . \ n \ b 3 . Initialize hash table sizes . The minsize should be a power of two . The maxsize should be > = minsize . Both values will be adjusted . The high and low marks are always set to be twice the table size and half the table size respectively . When the number of nodes in the table grows beyond the high size ( beyond load factor 2 ) it will double in size to cut the load factor down to about about 1 . If the table shrinks down to or beneath load factor 0 . 5 it will shrink bringing the load up to about 1 . However the table will never shrink beneath minsize even if it ' s emptied . \ n \ b 4 . Allocate the table of hash chains . \ n \ b 5 . Finish initializing the hash structure and the table . \ b 6 . This indicates that the table is dynamically allocated and dynamically resized on the fly . A table that has this value set to zero is assumed to be statically allocated and will not be resized . \ n \ b 7 . The table of chains must be properly reset to all null pointers . \ b 8 . Verify table ' s correctness if self - verification is true . \ param isdynamic The hash table is [ not ] automatically grow . If set to false the hash table is initialized t be fixed at minsize and maxsize is ignored . \ 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 . \ return Newly created empty hash table . \ exception " Verification Failed " Only if \ ref hash_self_verify enabled .
hash_t *hash_table_create(bool_t isdynamic,
                          hashcount_t minsize,
                          hashcount_t maxsize,
                          hash_comp_t compfun,
                          hash_fun_t hashfun,
                          hnode_data_free_t freedatafun)
{
  hash_t *hash;
  LOGDIAG4CALL(_TBOOL(isdynamic), _TULONG(minsize), _TULONG(maxsize),
      _TPTR(compfun), _TPTR(hashfun), _TPTR(freedatafun));
  if( hash_val_t_bit == 0 )
  {
    compute_bits();
  }
  hash = NEW(hash_t);
  init_hash_sizes(hash, minsize, maxsize);
  hash->table = (hnode_t **)new(sizeof(hnode_t *) * hash->minsize);
  hash->nchains       = minsize;
  hash->mask          = compute_mask(hash->nchains);
  hash->count         = 0;
  hash->compare       = compfun ? compfun : hash_comp_default;
  hash->hash          = hashfun ? hashfun : hash_fun_default;
  hash->freenodedata  = freedatafun;
  hash->dynamic       = isdynamic;
  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_create ( bool_t isdynamic , hashcount_t minsize , hashcount_t maxsize , hash_comp_t compfun , hash_fun_t hashfun , hnode_data_free_t freedatafun ) { hash_t * hash ; LOGDIAG4CALL ( _TBOOL ( isdynamic ) , _TULONG ( minsize ) , _TULONG ( maxsize ) , _TPTR ( compfun ) , _TPTR ( hashfun ) , _TPTR ( freedatafun ) ) ; if ( hash_val_t_bit == 0 ) { compute_bits ( ) ; } hash = NEW ( hash_t ) ; init_hash_sizes ( hash , minsize , maxsize ) ; hash -> table = ( hnode_t * * ) new ( sizeof ( hnode_t * ) * hash -> minsize ) ; hash -> nchains = minsize ; hash -> mask = compute_mask ( hash -> nchains ) ; hash -> count = 0 ; hash -> compare = compfun ? compfun : hash_comp_default ; hash -> hash = hashfun ? hashfun : hash_fun_default ; hash -> freenodedata = freedatafun ; hash -> dynamic = isdynamic ; 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 Create a dynamic hash table.
\ brief Create a dynamic hash table .
// Step 1 // Step 2 // Step 3 // Step 4 // Step 5 // Step 6 // Step 7 // Step 8