FreeBSD/usr.bin/grep/regex/hashtable.c
/*
 * Initializes a hash table that can hold table_size number of entries,
 * each of which has a key of key_size bytes and a value of value_size
 * bytes. On successful allocation returns a pointer to the hash table.
 * Otherwise, returns NULL and sets errno to indicate the error.
 */
Initializes a hash table that can hold table_size number of entries,
each of which has a key of key_size bytes and a value of value_size
bytes. On successful allocation returns a pointer to the hash table.
Otherwise, returns NULL and sets errno to indicate the error.
Initializes a hash table that can hold table_size number of entries each of which has a key of key_size bytes and a value of value_size bytes . On successful allocation returns a pointer to the hash table . Otherwise returns NULL and sets errno to indicate the error .
hashtable
*hashtable_init(size_t table_size, size_t key_size, size_t value_size)
{
  hashtable *tbl;
  DPRINT(("hashtable_init: table_size %zu, key_size %zu, value_size %zu\n",
	  table_size, key_size, value_size));
  tbl = malloc(sizeof(hashtable));
  if (tbl == NULL)
    goto mem1;
  tbl->entries = calloc(sizeof(hashtable_entry *), table_size);
  if (tbl->entries == NULL)
    goto mem2;
  tbl->table_size = table_size;
  tbl->usage = 0;
  tbl->key_size = key_size;
  tbl->value_size = value_size;
  return (tbl);
mem2:
  free(tbl);
mem1:
  DPRINT(("hashtable_init: allocation failed\n"));
  errno = ENOMEM;
  return (NULL);
}
hashtable * hashtable_init ( size_t table_size , size_t key_size , size_t value_size ) { hashtable * tbl ; DPRINT ( ( " \n " , table_size , key_size , value_size ) ) ; tbl = malloc ( sizeof ( hashtable ) ) ; if ( tbl == NULL ) goto mem1 ; tbl -> entries = calloc ( sizeof ( hashtable_entry * ) , table_size ) ; if ( tbl -> entries == NULL ) goto mem2 ; tbl -> table_size = table_size ; tbl -> usage = 0 ; tbl -> key_size = key_size ; tbl -> value_size = value_size ; return ( tbl ) ; mem2 : free ( tbl ) ; mem1 : DPRINT ( ( " \n " ) ) ; errno = ENOMEM ; return ( NULL ) ; }
Initializes a hash table that can hold table_size number of entries,
 each of which has a key of key_size bytes and a value of value_size
 bytes.
Initializes a hash table that can hold table_size number of entries each of which has a key of key_size bytes and a value of value_size bytes .