mariadb/include/hash0hash.ic

145 lines
3.2 KiB
Text
Raw Normal View History

2005-10-27 07:29:40 +00:00
/******************************************************
The simple hash table utility
(c) 1997 Innobase Oy
Created 5/20/1997 Heikki Tuuri
*******************************************************/
#include "ut0rnd.h"
/****************************************************************
Gets the nth cell in a hash table. */
UNIV_INLINE
hash_cell_t*
hash_get_nth_cell(
/*==============*/
/* out: pointer to cell */
hash_table_t* table, /* in: hash table */
ulint n) /* in: cell index */
2005-10-27 07:29:40 +00:00
{
ut_ad(n < table->n_cells);
return(table->array + n);
}
/*****************************************************************
Clears a hash table so that all the cells become empty. */
UNIV_INLINE
void
hash_table_clear(
/*=============*/
hash_table_t* table) /* in/out: hash table */
{
memset(table->array, 0x0,
table->n_cells * sizeof(*table->array));
}
2005-10-27 07:29:40 +00:00
/*****************************************************************
Returns the number of cells in a hash table. */
UNIV_INLINE
ulint
hash_get_n_cells(
/*=============*/
/* out: number of cells */
hash_table_t* table) /* in: table */
{
return(table->n_cells);
}
/******************************************************************
Calculates the hash value from a folded value. */
UNIV_INLINE
ulint
hash_calc_hash(
/*===========*/
/* out: hashed value */
ulint fold, /* in: folded value */
hash_table_t* table) /* in: hash table */
{
return(ut_hash_ulint(fold, table->n_cells));
}
/****************************************************************
Gets the mutex index for a fold value in a hash table. */
UNIV_INLINE
ulint
hash_get_mutex_no(
/*==============*/
/* out: mutex number */
hash_table_t* table, /* in: hash table */
ulint fold) /* in: fold */
2005-10-27 07:29:40 +00:00
{
ut_ad(ut_is_2pow(table->n_mutexes));
branches/innodb+: Merge revisions 3579:3599 from branches/zip: ------------------------------------------------------------------------ r3589 | marko | 2008-12-18 15:24:44 +0200 (Thu, 18 Dec 2008) | 2 lines branches/zip: ha_innodb.cc: Do not include some unnecessary MySQL header files. ------------------------------------------------------------------------ r3594 | marko | 2008-12-19 13:58:13 +0200 (Fri, 19 Dec 2008) | 4 lines branches/zip: HASH_INSERT, HASH_DELETE: Add explicit type conversions, so that the macros will expand to valid C++. Unlike C++, C allows implicit type conversions from void* to other pointer types. ------------------------------------------------------------------------ r3597 | marko | 2008-12-22 12:27:16 +0200 (Mon, 22 Dec 2008) | 3 lines branches/zip: Pass the caller's file name and line number to row_mysql_lock_data_dictionary(), row_mysql_freeze_data_dictionary(), to better track down locking issues that involve dict_operation_lock. ------------------------------------------------------------------------ r3599 | marko | 2008-12-22 15:41:47 +0200 (Mon, 22 Dec 2008) | 36 lines branches/zip: Merge revisions 3479:3598 from branches/5.1: ------------------------------------------------------------------------ r3588 | inaam | 2008-12-18 14:26:54 +0200 (Thu, 18 Dec 2008) | 8 lines branches/5.1 It is a bug in unused code. If we don't calculate the hash value when calculating the mutex number then two pages which map to same hash value can get two different mutex numbers. Approved by: Marko ------------------------------------------------------------------------ r3590 | marko | 2008-12-18 15:33:36 +0200 (Thu, 18 Dec 2008) | 11 lines branches/5.1: When converting a record to MySQL format, copy the default column values for columns that are SQL NULL. This addresses failures in row-based replication (Bug #39648). row_prebuilt_t: Add default_rec, for the default values of the columns in MySQL format. row_sel_store_mysql_rec(): Use prebuilt->default_rec instead of padding columns. rb://64 approved by Heikki Tuuri ------------------------------------------------------------------------ r3598 | marko | 2008-12-22 15:28:03 +0200 (Mon, 22 Dec 2008) | 6 lines branches/5.1: ibuf_delete_rec(): When the record cannot be found and the tablespace has been dropped, commit the mini-transaction, so that InnoDB will not hold the insert buffer tree latch in exclusive mode, causing a potential deadlock. This bug was introduced in the fix of Bug #27276 in r2924. ------------------------------------------------------------------------ ------------------------------------------------------------------------
2008-12-22 14:02:10 +00:00
return(ut_2pow_remainder(hash_calc_hash(fold, table),
table->n_mutexes));
2005-10-27 07:29:40 +00:00
}
/****************************************************************
Gets the nth heap in a hash table. */
UNIV_INLINE
mem_heap_t*
hash_get_nth_heap(
/*==============*/
/* out: mem heap */
hash_table_t* table, /* in: hash table */
ulint i) /* in: index of the heap */
2005-10-27 07:29:40 +00:00
{
ut_ad(i < table->n_mutexes);
return(table->heaps[i]);
}
/****************************************************************
Gets the heap for a fold value in a hash table. */
UNIV_INLINE
mem_heap_t*
hash_get_heap(
/*==========*/
/* out: mem heap */
hash_table_t* table, /* in: hash table */
ulint fold) /* in: fold */
2005-10-27 07:29:40 +00:00
{
ulint i;
if (table->heap) {
return(table->heap);
}
i = hash_get_mutex_no(table, fold);
return(hash_get_nth_heap(table, i));
}
/****************************************************************
Gets the nth mutex in a hash table. */
UNIV_INLINE
mutex_t*
hash_get_nth_mutex(
/*===============*/
/* out: mutex */
hash_table_t* table, /* in: hash table */
ulint i) /* in: index of the mutex */
2005-10-27 07:29:40 +00:00
{
ut_ad(i < table->n_mutexes);
2005-10-27 07:29:40 +00:00
return(table->mutexes + i);
}
/****************************************************************
Gets the mutex for a fold value in a hash table. */
UNIV_INLINE
mutex_t*
hash_get_mutex(
/*===========*/
/* out: mutex */
hash_table_t* table, /* in: hash table */
ulint fold) /* in: fold */
2005-10-27 07:29:40 +00:00
{
ulint i;
i = hash_get_mutex_no(table, fold);
return(hash_get_nth_mutex(table, i));
}