1
/************************************************************************
2
The hash table with external chains
4
(c) 1994-1997 Innobase Oy
6
Created 8/18/1994 Heikki Tuuri
7
*************************************************************************/
12
/***************************************************************
13
Deletes a hash node. */
18
hash_table_t* table, /* in: hash table */
19
ha_node_t* del_node); /* in: node to be deleted */
21
/**********************************************************************
22
Gets a hash node data. */
27
/* out: pointer to the data */
28
ha_node_t* node) /* in: hash chain node */
33
/**********************************************************************
34
Sets hash node data. */
37
ha_node_set_data_func(
38
/*==================*/
39
ha_node_t* node, /* in: hash chain node */
41
buf_block_t* block, /* in: buffer block containing the data */
42
#endif /* UNIV_DEBUG */
43
void* data) /* in: pointer to the data */
47
#endif /* UNIV_DEBUG */
52
# define ha_node_set_data(n,b,d) ha_node_set_data_func(n,b,d)
53
#else /* UNIV_DEBUG */
54
# define ha_node_set_data(n,b,d) ha_node_set_data_func(n,d)
55
#endif /* UNIV_DEBUG */
57
/**********************************************************************
58
Gets the next node in a hash chain. */
63
/* out: next node, NULL if none */
64
ha_node_t* node) /* in: hash chain node */
69
/**********************************************************************
70
Gets the first node in a hash chain. */
75
/* out: first node, NULL if none */
76
hash_table_t* table, /* in: hash table */
77
ulint fold) /* in: fold value determining the chain */
80
hash_get_nth_cell(table, hash_calc_hash(fold, table))->node);
83
/*****************************************************************
84
Looks for an element in a hash table. */
89
/* out: pointer to the first hash table node
90
in chain having the fold number, NULL if not
92
hash_table_t* table, /* in: hash table */
93
ulint fold) /* in: folded value of the searched data */
97
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
99
node = ha_chain_get_first(table, fold);
102
if (node->fold == fold) {
107
node = ha_chain_get_next(node);
113
/*****************************************************************
114
Looks for an element in a hash table. */
117
ha_search_and_get_data(
118
/*===================*/
119
/* out: pointer to the data of the first hash
120
table node in chain having the fold number,
122
hash_table_t* table, /* in: hash table */
123
ulint fold) /* in: folded value of the searched data */
127
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
129
node = ha_chain_get_first(table, fold);
132
if (node->fold == fold) {
137
node = ha_chain_get_next(node);
143
/*************************************************************
144
Looks for an element when we know the pointer to the data. */
149
/* out: pointer to the hash table node, NULL
150
if not found in the table */
151
hash_table_t* table, /* in: hash table */
152
ulint fold, /* in: folded value of the searched data */
153
void* data) /* in: pointer to the data */
157
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
159
node = ha_chain_get_first(table, fold);
162
if (node->data == data) {
167
node = ha_chain_get_next(node);
173
/*************************************************************
174
Looks for an element when we know the pointer to the data, and deletes
175
it from the hash table, if found. */
178
ha_search_and_delete_if_found(
179
/*==========================*/
180
/* out: TRUE if found */
181
hash_table_t* table, /* in: hash table */
182
ulint fold, /* in: folded value of the searched data */
183
void* data) /* in: pointer to the data */
187
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
189
node = ha_search_with_data(table, fold, data);
192
ha_delete_hash_node(table, node);