1
/*****************************************************************************
3
Copyright (C) 1994, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/********************************************************************//**
20
@file include/ha0ha.ic
21
The hash table with external chains
23
Created 8/18/1994 Heikki Tuuri
24
*************************************************************************/
29
/***********************************************************//**
30
Deletes a hash node. */
35
hash_table_t* table, /*!< in: hash table */
36
ha_node_t* del_node); /*!< in: node to be deleted */
38
/******************************************************************//**
39
Gets a hash node data.
40
@return pointer to the data */
45
ha_node_t* node) /*!< in: hash chain node */
50
/******************************************************************//**
51
Sets hash node data. */
54
ha_node_set_data_func(
55
/*==================*/
56
ha_node_t* node, /*!< in: hash chain node */
57
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
58
buf_block_t* block, /*!< in: buffer block containing the data */
59
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
60
void* data) /*!< in: pointer to the data */
62
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
64
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
68
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
69
/** Sets hash node data.
70
@param n in: hash chain node
71
@param b in: buffer block containing the data
72
@param d in: pointer to the data */
73
# define ha_node_set_data(n,b,d) ha_node_set_data_func(n,b,d)
74
#else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
75
/** Sets hash node data.
76
@param n in: hash chain node
77
@param b in: buffer block containing the data
78
@param d in: pointer to the data */
79
# define ha_node_set_data(n,b,d) ha_node_set_data_func(n,d)
80
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
82
/******************************************************************//**
83
Gets the next node in a hash chain.
84
@return next node, NULL if none */
89
ha_node_t* node) /*!< in: hash chain node */
94
/******************************************************************//**
95
Gets the first node in a hash chain.
96
@return first node, NULL if none */
101
hash_table_t* table, /*!< in: hash table */
102
ulint fold) /*!< in: fold value determining the chain */
105
hash_get_nth_cell(table, hash_calc_hash(fold, table))->node);
108
/*************************************************************//**
109
Looks for an element in a hash table.
110
@return pointer to the first hash table node in chain having the fold
111
number, NULL if not found */
116
hash_table_t* table, /*!< in: hash table */
117
ulint fold) /*!< in: folded value of the searched data */
121
ASSERT_HASH_MUTEX_OWN(table, fold);
123
node = ha_chain_get_first(table, fold);
126
if (node->fold == fold) {
131
node = ha_chain_get_next(node);
137
/*************************************************************//**
138
Looks for an element in a hash table.
139
@return pointer to the data of the first hash table node in chain
140
having the fold number, NULL if not found */
143
ha_search_and_get_data(
144
/*===================*/
145
hash_table_t* table, /*!< in: hash table */
146
ulint fold) /*!< in: folded value of the searched data */
150
ASSERT_HASH_MUTEX_OWN(table, fold);
152
node = ha_chain_get_first(table, fold);
155
if (node->fold == fold) {
160
node = ha_chain_get_next(node);
166
/*********************************************************//**
167
Looks for an element when we know the pointer to the data.
168
@return pointer to the hash table node, NULL if not found in the table */
173
hash_table_t* table, /*!< in: hash table */
174
ulint fold, /*!< in: folded value of the searched data */
175
void* data) /*!< in: pointer to the data */
179
ASSERT_HASH_MUTEX_OWN(table, fold);
181
node = ha_chain_get_first(table, fold);
184
if (node->data == data) {
189
node = ha_chain_get_next(node);
195
/*********************************************************//**
196
Looks for an element when we know the pointer to the data, and deletes
197
it from the hash table, if found.
198
@return TRUE if found */
201
ha_search_and_delete_if_found(
202
/*==========================*/
203
hash_table_t* table, /*!< in: hash table */
204
ulint fold, /*!< in: folded value of the searched data */
205
void* data) /*!< in: pointer to the data */
209
ASSERT_HASH_MUTEX_OWN(table, fold);
211
node = ha_search_with_data(table, fold, data);
214
ha_delete_hash_node(table, node);