/*************************************************************//** Creates a hash table with >= n array cells. The actual number of cells is chosen to be a prime number slightly bigger than n. @return own: created table */ UNIV_INTERN hash_table_t* hash_create( /*========*/ ulint n) /*!< in: number of array cells */ { hash_cell_t* array; ulint prime; hash_table_t* table; prime = ut_find_prime(n); table = mem_alloc(sizeof(hash_table_t)); array = ut_malloc(sizeof(hash_cell_t) * prime); table->array = array; table->n_cells = prime; #ifndef UNIV_HOTBACKUP # if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG table->adaptive = FALSE; # endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ table->n_mutexes = 0; table->mutexes = NULL; table->heaps = NULL; #endif /* !UNIV_HOTBACKUP */ table->heap = NULL; ut_d(table->magic_n = HASH_TABLE_MAGIC_N); /* Initialize the cell array */ hash_table_clear(table); return(table); }
hash_table_t* hash_create( /*========*/ /* out, own: created table */ ulint n) /* in: number of array cells */ { hash_cell_t* array; ulint prime; hash_table_t* table; ulint i; hash_cell_t* cell; prime = ut_find_prime(n); table = mem_alloc(sizeof(hash_table_t)); array = ut_malloc(sizeof(hash_cell_t) * prime); table->array = array; table->n_cells = prime; table->n_mutexes = 0; table->mutexes = NULL; table->heaps = NULL; table->heap = NULL; table->magic_n = HASH_TABLE_MAGIC_N; /* Initialize the cell array */ for (i = 0; i < prime; i++) { cell = hash_get_nth_cell(table, i); cell->node = NULL; } return(table); }