From 88e146442ce915d23818480a980ecc68c4d611a7 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Sun, 2 May 2010 20:52:08 +0000 Subject: [PATCH] bugfix in function h5priv_hresize(), some comments added --- src/h5core/h5_hsearch.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/h5core/h5_hsearch.c b/src/h5core/h5_hsearch.c index 7bee90b..bde99e3 100644 --- a/src/h5core/h5_hsearch.c +++ b/src/h5core/h5_hsearch.c @@ -90,19 +90,18 @@ h5priv_hcreate ( } /* - Grow hash table. Do nothing if requested number of elements is less than - or equal the current size. + Grow hash table. */ h5_err_t h5priv_hresize ( h5_file_t * const f, - size_t nel, - h5_hashtable_t *htab + size_t nel, // number of entries to grow + h5_hashtable_t *htab // hash table to resize ) { if ( htab == NULL || htab->table == NULL ) { h5_error_internal ( f, __FILE__, __func__, __LINE__ ); } - if ( htab->size >= nel ) return H5_SUCCESS; + // create new hash table h5_hashtable_t __htab; memset ( &__htab, 0, sizeof ( __htab ) ); nel += htab->size; @@ -110,6 +109,8 @@ h5priv_hresize ( htab->size, nel ); TRY ( h5priv_hcreate ( f, nel, &__htab, htab->compare, htab->compute_hash ) ); + + // add all entries to new hash table unsigned int idx; for ( idx = 1; idx <= htab->size; idx++ ) { if ( htab->table[idx].used ) { @@ -122,6 +123,7 @@ h5priv_hresize ( &__htab ); } } + // destroy old hash table TRY ( h5priv_hdestroy ( f, htab ) ); *htab = __htab; return H5_SUCCESS;