2005-10-27 09:29:40 +02:00
|
|
|
/******************************************************
|
|
|
|
The simple hash table utility
|
|
|
|
|
|
|
|
(c) 1997 Innobase Oy
|
|
|
|
|
|
|
|
Created 5/20/1997 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#ifndef hash0hash_h
|
|
|
|
#define hash0hash_h
|
|
|
|
|
|
|
|
#include "univ.i"
|
|
|
|
#include "mem0mem.h"
|
|
|
|
#include "sync0sync.h"
|
|
|
|
|
|
|
|
typedef struct hash_table_struct hash_table_t;
|
|
|
|
typedef struct hash_cell_struct hash_cell_t;
|
|
|
|
|
|
|
|
typedef void* hash_node_t;
|
|
|
|
|
2007-02-02 12:31:29 +01:00
|
|
|
/* Fix Bug #13859: symbol collision between imap/mysql */
|
|
|
|
#define hash_create hash0_create
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/*****************************************************************
|
|
|
|
Creates a hash table with >= n array cells. The actual number
|
|
|
|
of cells is chosen to be a prime number slightly bigger than n. */
|
2008-02-18 19:38:33 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
hash_table_t*
|
|
|
|
hash_create(
|
|
|
|
/*========*/
|
|
|
|
/* out, own: created table */
|
|
|
|
ulint n); /* in: number of array cells */
|
|
|
|
/*****************************************************************
|
|
|
|
Creates a mutex array to protect a hash table. */
|
2008-02-18 19:38:33 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
2006-11-21 11:09:14 +01:00
|
|
|
hash_create_mutexes_func(
|
|
|
|
/*=====================*/
|
2005-10-27 09:29:40 +02:00
|
|
|
hash_table_t* table, /* in: hash table */
|
2006-11-21 11:09:14 +01:00
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
ulint sync_level, /* in: latching order level of the
|
2005-10-27 09:29:40 +02:00
|
|
|
mutexes: used in the debug version */
|
2006-11-21 11:09:14 +01:00
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
ulint n_mutexes); /* in: number of mutexes */
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
# define hash_create_mutexes(t,n,level) hash_create_mutexes_func(t,level,n)
|
|
|
|
#else /* UNIV_SYNC_DEBUG */
|
|
|
|
# define hash_create_mutexes(t,n,level) hash_create_mutexes_func(t,n)
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/*****************************************************************
|
|
|
|
Frees a hash table. */
|
2008-02-18 19:38:33 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
hash_table_free(
|
|
|
|
/*============*/
|
|
|
|
hash_table_t* table); /* in, own: hash table */
|
|
|
|
/******************************************************************
|
|
|
|
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 */
|
|
|
|
/************************************************************************
|
|
|
|
Assert that the mutex for the table in a hash operation is owned. */
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
# define HASH_ASSERT_OWNED(TABLE, FOLD) \
|
|
|
|
ut_ad(!(TABLE)->mutexes || mutex_own(hash_get_mutex(TABLE, FOLD)));
|
|
|
|
#else
|
|
|
|
# define HASH_ASSERT_OWNED(TABLE, FOLD)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Inserts a struct to a hash table. */
|
|
|
|
|
|
|
|
#define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)\
|
|
|
|
do {\
|
|
|
|
hash_cell_t* cell3333;\
|
|
|
|
TYPE* struct3333;\
|
|
|
|
\
|
|
|
|
HASH_ASSERT_OWNED(TABLE, FOLD)\
|
|
|
|
\
|
|
|
|
(DATA)->NAME = NULL;\
|
|
|
|
\
|
|
|
|
cell3333 = hash_get_nth_cell(TABLE, hash_calc_hash(FOLD, TABLE));\
|
|
|
|
\
|
|
|
|
if (cell3333->node == NULL) {\
|
|
|
|
cell3333->node = DATA;\
|
|
|
|
} else {\
|
2008-09-17 21:52:30 +02:00
|
|
|
struct3333 = (TYPE*) cell3333->node;\
|
2005-10-27 09:29:40 +02:00
|
|
|
\
|
|
|
|
while (struct3333->NAME != NULL) {\
|
|
|
|
\
|
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 15:02:10 +01:00
|
|
|
struct3333 = (TYPE*) struct3333->NAME;\
|
2005-10-27 09:29:40 +02:00
|
|
|
}\
|
|
|
|
\
|
|
|
|
struct3333->NAME = DATA;\
|
|
|
|
}\
|
|
|
|
} while (0)
|
|
|
|
|
2007-01-24 12:41:19 +01:00
|
|
|
#ifdef UNIV_HASH_DEBUG
|
|
|
|
# define HASH_ASSERT_VALID(DATA) ut_a((void*) (DATA) != (void*) -1)
|
|
|
|
# define HASH_INVALIDATE(DATA, NAME) DATA->NAME = (void*) -1
|
|
|
|
#else
|
|
|
|
# define HASH_ASSERT_VALID(DATA) do {} while (0)
|
|
|
|
# define HASH_INVALIDATE(DATA, NAME) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
Deletes a struct from a hash table. */
|
|
|
|
|
|
|
|
#define HASH_DELETE(TYPE, NAME, TABLE, FOLD, DATA)\
|
|
|
|
do {\
|
|
|
|
hash_cell_t* cell3333;\
|
|
|
|
TYPE* struct3333;\
|
|
|
|
\
|
|
|
|
HASH_ASSERT_OWNED(TABLE, FOLD)\
|
|
|
|
\
|
|
|
|
cell3333 = hash_get_nth_cell(TABLE, hash_calc_hash(FOLD, TABLE));\
|
|
|
|
\
|
|
|
|
if (cell3333->node == DATA) {\
|
2007-01-24 12:41:19 +01:00
|
|
|
HASH_ASSERT_VALID(DATA->NAME);\
|
2005-10-27 09:29:40 +02:00
|
|
|
cell3333->node = DATA->NAME;\
|
|
|
|
} else {\
|
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 15:02:10 +01:00
|
|
|
struct3333 = (TYPE*) cell3333->node;\
|
2005-10-27 09:29:40 +02:00
|
|
|
\
|
|
|
|
while (struct3333->NAME != DATA) {\
|
|
|
|
\
|
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 15:02:10 +01:00
|
|
|
struct3333 = (TYPE*) struct3333->NAME;\
|
2006-03-03 15:43:05 +01:00
|
|
|
ut_a(struct3333);\
|
2005-10-27 09:29:40 +02:00
|
|
|
}\
|
|
|
|
\
|
|
|
|
struct3333->NAME = DATA->NAME;\
|
|
|
|
}\
|
2007-01-24 12:41:19 +01:00
|
|
|
HASH_INVALIDATE(DATA, NAME);\
|
2005-10-27 09:29:40 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Gets the first struct in a hash chain, NULL if none. */
|
|
|
|
|
|
|
|
#define HASH_GET_FIRST(TABLE, HASH_VAL)\
|
|
|
|
(hash_get_nth_cell(TABLE, HASH_VAL)->node)
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Gets the next struct in a hash chain, NULL if none. */
|
|
|
|
|
|
|
|
#define HASH_GET_NEXT(NAME, DATA) ((DATA)->NAME)
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Looks for a struct in a hash table. */
|
2007-08-01 10:13:22 +02:00
|
|
|
#define HASH_SEARCH(NAME, TABLE, FOLD, TYPE, DATA, TEST)\
|
2005-10-27 09:29:40 +02:00
|
|
|
{\
|
|
|
|
\
|
|
|
|
HASH_ASSERT_OWNED(TABLE, FOLD)\
|
|
|
|
\
|
2007-08-01 10:13:22 +02:00
|
|
|
(DATA) = (TYPE) HASH_GET_FIRST(TABLE, hash_calc_hash(FOLD, TABLE));\
|
2007-01-24 12:41:19 +01:00
|
|
|
HASH_ASSERT_VALID(DATA);\
|
2005-10-27 09:29:40 +02:00
|
|
|
\
|
|
|
|
while ((DATA) != NULL) {\
|
|
|
|
if (TEST) {\
|
|
|
|
break;\
|
|
|
|
} else {\
|
2007-01-24 12:41:19 +01:00
|
|
|
HASH_ASSERT_VALID(HASH_GET_NEXT(NAME, DATA));\
|
2007-08-01 10:13:22 +02:00
|
|
|
(DATA) = (TYPE) HASH_GET_NEXT(NAME, DATA);\
|
2005-10-27 09:29:40 +02:00
|
|
|
}\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
Gets the nth cell in a hash table. */
|
|
|
|
UNIV_INLINE
|
|
|
|
hash_cell_t*
|
|
|
|
hash_get_nth_cell(
|
|
|
|
/*==============*/
|
|
|
|
/* out: pointer to cell */
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint n); /* in: cell index */
|
2007-08-22 11:43:45 +02:00
|
|
|
|
|
|
|
/*****************************************************************
|
2007-08-23 09:01:24 +02:00
|
|
|
Clears a hash table so that all the cells become empty. */
|
2007-08-22 11:43:45 +02:00
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
hash_table_clear(
|
|
|
|
/*=============*/
|
|
|
|
hash_table_t* table); /* in/out: hash table */
|
|
|
|
|
2005-10-27 09:29:40 +02: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 */
|
|
|
|
/***********************************************************************
|
|
|
|
Deletes a struct which is stored in the heap of the hash table, and compacts
|
|
|
|
the heap. The fold value must be stored in the struct NODE in a field named
|
|
|
|
'fold'. */
|
|
|
|
|
|
|
|
#define HASH_DELETE_AND_COMPACT(TYPE, NAME, TABLE, NODE)\
|
|
|
|
do {\
|
|
|
|
TYPE* node111;\
|
|
|
|
TYPE* top_node111;\
|
|
|
|
hash_cell_t* cell111;\
|
|
|
|
ulint fold111;\
|
|
|
|
\
|
|
|
|
fold111 = (NODE)->fold;\
|
|
|
|
\
|
|
|
|
HASH_DELETE(TYPE, NAME, TABLE, fold111, NODE);\
|
|
|
|
\
|
|
|
|
top_node111 = (TYPE*)mem_heap_get_top(\
|
|
|
|
hash_get_heap(TABLE, fold111),\
|
|
|
|
sizeof(TYPE));\
|
|
|
|
\
|
|
|
|
/* If the node to remove is not the top node in the heap, compact the\
|
|
|
|
heap of nodes by moving the top node in the place of NODE. */\
|
|
|
|
\
|
|
|
|
if (NODE != top_node111) {\
|
|
|
|
\
|
|
|
|
/* Copy the top node in place of NODE */\
|
|
|
|
\
|
|
|
|
*(NODE) = *top_node111;\
|
|
|
|
\
|
|
|
|
cell111 = hash_get_nth_cell(TABLE,\
|
|
|
|
hash_calc_hash(top_node111->fold, TABLE));\
|
|
|
|
\
|
|
|
|
/* Look for the pointer to the top node, to update it */\
|
|
|
|
\
|
|
|
|
if (cell111->node == top_node111) {\
|
|
|
|
/* The top node is the first in the chain */\
|
|
|
|
\
|
|
|
|
cell111->node = NODE;\
|
|
|
|
} else {\
|
|
|
|
/* We have to look for the predecessor of the top\
|
|
|
|
node */\
|
|
|
|
node111 = cell111->node;\
|
|
|
|
\
|
|
|
|
while (top_node111 != HASH_GET_NEXT(NAME, node111)) {\
|
|
|
|
\
|
|
|
|
node111 = HASH_GET_NEXT(NAME, node111);\
|
|
|
|
}\
|
|
|
|
\
|
|
|
|
/* Now we have the predecessor node */\
|
|
|
|
\
|
|
|
|
node111->NAME = NODE;\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
\
|
|
|
|
/* Free the space occupied by the top node */\
|
|
|
|
\
|
|
|
|
mem_heap_free_top(hash_get_heap(TABLE, fold111), sizeof(TYPE));\
|
|
|
|
} while (0)
|
|
|
|
|
2006-04-12 11:32:17 +02:00
|
|
|
/********************************************************************
|
|
|
|
Move all hash table entries from OLD_TABLE to NEW_TABLE.*/
|
|
|
|
|
|
|
|
#define HASH_MIGRATE(OLD_TABLE, NEW_TABLE, NODE_TYPE, PTR_NAME, FOLD_FUNC) \
|
|
|
|
do {\
|
|
|
|
ulint i2222;\
|
|
|
|
ulint cell_count2222;\
|
|
|
|
\
|
|
|
|
cell_count2222 = hash_get_n_cells(OLD_TABLE);\
|
|
|
|
\
|
|
|
|
for (i2222 = 0; i2222 < cell_count2222; i2222++) {\
|
|
|
|
NODE_TYPE* node2222 = HASH_GET_FIRST((OLD_TABLE), i2222);\
|
|
|
|
\
|
|
|
|
while (node2222) {\
|
|
|
|
NODE_TYPE* next2222 = node2222->PTR_NAME;\
|
|
|
|
ulint fold2222 = FOLD_FUNC(node2222);\
|
|
|
|
\
|
|
|
|
HASH_INSERT(NODE_TYPE, PTR_NAME, (NEW_TABLE),\
|
|
|
|
fold2222, node2222);\
|
|
|
|
\
|
|
|
|
node2222 = next2222;\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Gets the mutex index for a fold value in a hash table. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
hash_get_mutex_no(
|
|
|
|
/*==============*/
|
|
|
|
/* out: mutex number */
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint fold); /* in: fold */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Gets the nth heap in a hash table. */
|
|
|
|
UNIV_INLINE
|
|
|
|
mem_heap_t*
|
|
|
|
hash_get_nth_heap(
|
|
|
|
/*==============*/
|
|
|
|
/* out: mem heap */
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint i); /* in: index of the heap */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Gets the heap for a fold value in a hash table. */
|
|
|
|
UNIV_INLINE
|
|
|
|
mem_heap_t*
|
|
|
|
hash_get_heap(
|
|
|
|
/*==========*/
|
|
|
|
/* out: mem heap */
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint fold); /* in: fold */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Gets the nth mutex in a hash table. */
|
|
|
|
UNIV_INLINE
|
|
|
|
mutex_t*
|
|
|
|
hash_get_nth_mutex(
|
|
|
|
/*===============*/
|
|
|
|
/* out: mutex */
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint i); /* in: index of the mutex */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Gets the mutex for a fold value in a hash table. */
|
|
|
|
UNIV_INLINE
|
|
|
|
mutex_t*
|
|
|
|
hash_get_mutex(
|
|
|
|
/*===========*/
|
|
|
|
/* out: mutex */
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint fold); /* in: fold */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Reserves the mutex for a fold value in a hash table. */
|
2008-02-18 19:38:33 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
hash_mutex_enter(
|
|
|
|
/*=============*/
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint fold); /* in: fold */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Releases the mutex for a fold value in a hash table. */
|
2008-02-18 19:38:33 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
hash_mutex_exit(
|
|
|
|
/*============*/
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table, /* in: hash table */
|
|
|
|
ulint fold); /* in: fold */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Reserves all the mutexes of a hash table, in an ascending order. */
|
2008-02-18 19:38:33 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
hash_mutex_enter_all(
|
|
|
|
/*=================*/
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table); /* in: hash table */
|
2005-10-27 09:29:40 +02:00
|
|
|
/****************************************************************
|
|
|
|
Releases all the mutexes of a hash table. */
|
2008-02-18 19:38:33 +01:00
|
|
|
UNIV_INTERN
|
2005-10-27 09:29:40 +02:00
|
|
|
void
|
|
|
|
hash_mutex_exit_all(
|
|
|
|
/*================*/
|
2006-02-23 20:25:29 +01:00
|
|
|
hash_table_t* table); /* in: hash table */
|
2005-10-27 09:29:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
struct hash_cell_struct{
|
|
|
|
void* node; /* hash chain node, NULL if none */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The hash table structure */
|
|
|
|
struct hash_table_struct {
|
2008-12-17 13:48:23 +01:00
|
|
|
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
|
2005-10-27 09:29:40 +02:00
|
|
|
ibool adaptive;/* TRUE if this is the hash table of the
|
|
|
|
adaptive hash index */
|
2008-12-17 13:48:23 +01:00
|
|
|
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
|
2005-10-27 09:29:40 +02:00
|
|
|
ulint n_cells;/* number of cells in the hash table */
|
|
|
|
hash_cell_t* array; /* pointer to cell array */
|
|
|
|
ulint n_mutexes;/* if mutexes != NULL, then the number of
|
|
|
|
mutexes, must be a power of 2 */
|
|
|
|
mutex_t* mutexes;/* NULL, or an array of mutexes used to
|
|
|
|
protect segments of the hash table */
|
|
|
|
mem_heap_t** heaps; /* if this is non-NULL, hash chain nodes for
|
|
|
|
external chaining can be allocated from these
|
|
|
|
memory heaps; there are then n_mutexes many of
|
|
|
|
these heaps */
|
|
|
|
mem_heap_t* heap;
|
|
|
|
ulint magic_n;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define HASH_TABLE_MAGIC_N 76561114
|
|
|
|
|
|
|
|
#ifndef UNIV_NONINL
|
|
|
|
#include "hash0hash.ic"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|