~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/ha0ha.ic

  • Committer: lbieber
  • Date: 2010-10-02 19:48:35 UTC
  • mfrom: (1730.6.19 drizzle-make-lcov)
  • Revision ID: lbieber@orisndriz08-20101002194835-q5zd9qc4lvx1xnfo
Merge Hartmut - clean up lex, now require flex to build, also "make lcov" improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1994, 2009, Innobase Oy. All Rights Reserved.
4
 
 
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.
8
 
 
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.
12
 
 
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
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/********************************************************************//**
20
 
@file include/ha0ha.ic
21
 
The hash table with external chains
22
 
 
23
 
Created 8/18/1994 Heikki Tuuri
24
 
*************************************************************************/
25
 
 
26
 
#include "ut0rnd.h"
27
 
#include "mem0mem.h"
28
 
 
29
 
/***********************************************************//**
30
 
Deletes a hash node. */
31
 
UNIV_INTERN
32
 
void
33
 
ha_delete_hash_node(
34
 
/*================*/
35
 
        hash_table_t*   table,          /*!< in: hash table */
36
 
        ha_node_t*      del_node);      /*!< in: node to be deleted */
37
 
 
38
 
/******************************************************************//**
39
 
Gets a hash node data.
40
 
@return pointer to the data */
41
 
UNIV_INLINE
42
 
void*
43
 
ha_node_get_data(
44
 
/*=============*/
45
 
        ha_node_t*      node)   /*!< in: hash chain node */
46
 
{
47
 
        return(node->data);
48
 
}
49
 
 
50
 
/******************************************************************//**
51
 
Sets hash node data. */
52
 
UNIV_INLINE
53
 
void
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 */
61
 
{
62
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
63
 
        node->block = block;
64
 
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
65
 
        node->data = data;
66
 
}
67
 
 
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 */
81
 
 
82
 
/******************************************************************//**
83
 
Gets the next node in a hash chain.
84
 
@return next node, NULL if none */
85
 
UNIV_INLINE
86
 
ha_node_t*
87
 
ha_chain_get_next(
88
 
/*==============*/
89
 
        ha_node_t*      node)   /*!< in: hash chain node */
90
 
{
91
 
        return(node->next);
92
 
}
93
 
 
94
 
/******************************************************************//**
95
 
Gets the first node in a hash chain.
96
 
@return first node, NULL if none */
97
 
UNIV_INLINE
98
 
ha_node_t*
99
 
ha_chain_get_first(
100
 
/*===============*/
101
 
        hash_table_t*   table,  /*!< in: hash table */
102
 
        ulint           fold)   /*!< in: fold value determining the chain */
103
 
{
104
 
        return((ha_node_t*)
105
 
               hash_get_nth_cell(table, hash_calc_hash(fold, table))->node);
106
 
}
107
 
 
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 */
112
 
UNIV_INLINE
113
 
ha_node_t*
114
 
ha_search(
115
 
/*======*/
116
 
        hash_table_t*   table,  /*!< in: hash table */
117
 
        ulint           fold)   /*!< in: folded value of the searched data */
118
 
{
119
 
        ha_node_t*      node;
120
 
 
121
 
        ASSERT_HASH_MUTEX_OWN(table, fold);
122
 
 
123
 
        node = ha_chain_get_first(table, fold);
124
 
 
125
 
        while (node) {
126
 
                if (node->fold == fold) {
127
 
 
128
 
                        return(node);
129
 
                }
130
 
 
131
 
                node = ha_chain_get_next(node);
132
 
        }
133
 
 
134
 
        return(NULL);
135
 
}
136
 
 
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 */
141
 
UNIV_INLINE
142
 
void*
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 */
147
 
{
148
 
        ha_node_t*      node;
149
 
 
150
 
        ASSERT_HASH_MUTEX_OWN(table, fold);
151
 
 
152
 
        node = ha_chain_get_first(table, fold);
153
 
 
154
 
        while (node) {
155
 
                if (node->fold == fold) {
156
 
 
157
 
                        return(node->data);
158
 
                }
159
 
 
160
 
                node = ha_chain_get_next(node);
161
 
        }
162
 
 
163
 
        return(NULL);
164
 
}
165
 
 
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 */
169
 
UNIV_INLINE
170
 
ha_node_t*
171
 
ha_search_with_data(
172
 
/*================*/
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 */
176
 
{
177
 
        ha_node_t*      node;
178
 
 
179
 
        ASSERT_HASH_MUTEX_OWN(table, fold);
180
 
 
181
 
        node = ha_chain_get_first(table, fold);
182
 
 
183
 
        while (node) {
184
 
                if (node->data == data) {
185
 
 
186
 
                        return(node);
187
 
                }
188
 
 
189
 
                node = ha_chain_get_next(node);
190
 
        }
191
 
 
192
 
        return(NULL);
193
 
}
194
 
 
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 */
199
 
UNIV_INLINE
200
 
ibool
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 */
206
 
{
207
 
        ha_node_t*      node;
208
 
 
209
 
        ASSERT_HASH_MUTEX_OWN(table, fold);
210
 
 
211
 
        node = ha_search_with_data(table, fold, data);
212
 
 
213
 
        if (node) {
214
 
                ha_delete_hash_node(table, node);
215
 
 
216
 
                return(TRUE);
217
 
        }
218
 
 
219
 
        return(FALSE);
220
 
}