4602d18 * Resolves: bug #735464 Fix the loop limit used to initialize the table directory, was based on count, now limited to segment_count.

3 files Authored by jdennis 12 years ago, Committed by sgallagh 12 years ago,
    * Resolves: bug #735464 Fix the loop limit used to initialize the table directory, was based on count, now limited to segment_count.
    
    * Do not pre-allocate all buckets based on requested table size. This
      defeats the point of a dynamic hash table which adjusts it's memory
      usage depending upon the number of items it holds. Pre-allocation
      also runs afoul of the table contraction logic, if the table is
      pre-allocated to a large size it will subsequently try to compact it
      negating the pre-allocation. Now the initial allocation is
      restricted to one directory segment (i.e. table->segment_count == 1)
    
    * If the caller did not specify the directory_bits and segment_bits
      then compute them from the requested table size. The directory_size
      and segment_size must be powers of 2 to accmodate fast
      arithmetic. An optimal maximum number of buckets would be equal to
      the anticipated table size. If there were no collisions that would
      mean each item would be located in it's own bucket whose chain
      length is 1, the item would be immediatly found upon indexing into
      the bucket table.
    
    * There is a requirment there be at least one directory
      segment, however contract_table() failed to enforce this
      requirement. Add a check to enforce the requirement.
    
    * If hash_create() or hash_create_ex() failed it left the tbl
      parameter uninitialized but returned an error code. Now upon failure
      tbl is initialized to NULL as well as returning an error code.
    
    * Clean up how the directory and segment sizes were computed. It had
      been using a loop and shifting 1 bit at a time, now it shifts all
      the bits in one operation and assures at least one directory and
      segment are allocated.
    
    * In the event of an early exit from hash_create_ex() due to an error
      make sure all previously allocated resources are cleaned up by
      calling hash_destroy(). There was only one place this was
      missing. hash_destroy() blindly assumed the table had a directory,
      normally it would unless hash_destroy was called due to an early
      exit in hash_create_ex(). Modify hash_destroy() to check for the
      existence of the directory before cleaning up the directory
      contents.
    
    * Update the function documentation in dhash.h to explain each
      parameter of hash_create() and hash_create_ex().
    
    * Enhance dhash_test.c
      - To output the random seed used to intialize the random number
        generator and add command line option to set the random seed. This
        permits recreating a failed test run.
      - Add command line parameter to set the initial table size.
      - Use proper string to long conversion routines when reading command
        line parameters (e.g. strtoul() instead of atoi())
      - Add logic to make sure each test value is unique.
    
    * Add additional information to the debug output to show the computed
      directory_bits, segment_bits, sizes, etc.
    
    * Adjust the debug_level conditionals to be less verbose.
    
        
file modified
+87 -46
file modified
+58 -21
file modified
+37 -10