Logo Search packages:      
Sourcecode: log4c version File versions  Download package

sd_hash_t* sd_hash_new ( size_t  a_size,
const sd_hash_ops_t a_ops 
)

Creates a new hash table. One can customize the memory (de)allocation policy for keys and data stored in the hash table.

Parameters:
a_size the initial size of the array.
a_ops the hash operations. If NULL, then string keys are assumed and no memory (de)allocation is performed for keys and data.
Returns:
a dynamicaly allocated hash table.

Definition at line 60 of file hash.c.

{
    const static sd_hash_ops_t default_ops = {
      (void*) &sd_hash_hash_string,
      (void*) &strcmp,
      0, 0, 0, 0
    };
    
    sd_hash_t*          hash;
    sd_hash_iter_t**    tab;
    
    if (a_size == 0) a_size = SD_HASH_DEFAULT_SIZE;
    
    hash    = sd_calloc(1, sizeof(*hash));
    tab           = sd_calloc(a_size, sizeof(*tab));
    
    if (hash == 0 || tab == 0) {
      free(hash);
      free(tab);
      return 0;
    }
    
    hash->nelem   = 0;
    hash->size    = a_size;
    hash->tab     = tab;
    hash->ops     = a_ops != 0 ? a_ops : &default_ops;
    
    return hash;
}


Generated by  Doxygen 1.6.0   Back to index