~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ha0ha.h

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

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.h
 
1
/******************************************************
21
2
The hash table with external chains
22
3
 
 
4
(c) 1994-1997 Innobase Oy
 
5
 
23
6
Created 8/18/1994 Heikki Tuuri
24
7
*******************************************************/
25
8
 
32
15
#include "page0types.h"
33
16
#include "buf0types.h"
34
17
 
35
 
/*************************************************************//**
36
 
Looks for an element in a hash table.
37
 
@return pointer to the data of the first hash table node in chain
38
 
having the fold number, NULL if not found */
 
18
/*****************************************************************
 
19
Looks for an element in a hash table. */
39
20
UNIV_INLINE
40
21
void*
41
22
ha_search_and_get_data(
42
23
/*===================*/
43
 
        hash_table_t*   table,  /*!< in: hash table */
44
 
        ulint           fold);  /*!< in: folded value of the searched data */
45
 
/*********************************************************//**
 
24
                                /* out: pointer to the data of the first hash
 
25
                                table node in chain having the fold number,
 
26
                                NULL if not found */
 
27
        hash_table_t*   table,  /* in: hash table */
 
28
        ulint           fold);  /* in: folded value of the searched data */
 
29
/*************************************************************
46
30
Looks for an element when we know the pointer to the data and updates
47
31
the pointer to data if found. */
48
32
UNIV_INTERN
49
33
void
50
34
ha_search_and_update_if_found_func(
51
35
/*===============================*/
52
 
        hash_table_t*   table,  /*!< in/out: hash table */
53
 
        ulint           fold,   /*!< in: folded value of the searched data */
54
 
        void*           data,   /*!< in: pointer to the data */
55
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
56
 
        buf_block_t*    new_block,/*!< in: block containing new_data */
57
 
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
58
 
        void*           new_data);/*!< in: new pointer to the data */
 
36
        hash_table_t*   table,  /* in: hash table */
 
37
        ulint           fold,   /* in: folded value of the searched data */
 
38
        void*           data,   /* in: pointer to the data */
 
39
#ifdef UNIV_DEBUG
 
40
        buf_block_t*    new_block,/* in: block containing new_data */
 
41
#endif
 
42
        void*           new_data);/* in: new pointer to the data */
59
43
 
60
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
61
 
/** Looks for an element when we know the pointer to the data and
62
 
updates the pointer to data if found.
63
 
@param table            in/out: hash table
64
 
@param fold             in: folded value of the searched data
65
 
@param data             in: pointer to the data
66
 
@param new_block        in: block containing new_data
67
 
@param new_data         in: new pointer to the data */
 
44
#ifdef UNIV_DEBUG
68
45
# define ha_search_and_update_if_found(table,fold,data,new_block,new_data) \
69
46
        ha_search_and_update_if_found_func(table,fold,data,new_block,new_data)
70
 
#else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
71
 
/** Looks for an element when we know the pointer to the data and
72
 
updates the pointer to data if found.
73
 
@param table            in/out: hash table
74
 
@param fold             in: folded value of the searched data
75
 
@param data             in: pointer to the data
76
 
@param new_block        ignored: block containing new_data
77
 
@param new_data         in: new pointer to the data */
 
47
#else
78
48
# define ha_search_and_update_if_found(table,fold,data,new_block,new_data) \
79
49
        ha_search_and_update_if_found_func(table,fold,data,new_data)
80
 
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
81
 
/*************************************************************//**
82
 
Creates a hash table with at least n array cells.  The actual number
83
 
of cells is chosen to be a prime number slightly bigger than n.
84
 
@return own: created table */
 
50
#endif
 
51
/*****************************************************************
 
52
Creates a hash table with >= n array cells. The actual number of cells is
 
53
chosen to be a prime number slightly bigger than n. */
85
54
UNIV_INTERN
86
55
hash_table_t*
87
56
ha_create_func(
88
57
/*===========*/
89
 
        ulint   n,              /*!< in: number of array cells */
 
58
                                /* out, own: created table */
 
59
        ulint   n,              /* in: number of array cells */
90
60
#ifdef UNIV_SYNC_DEBUG
91
 
        ulint   mutex_level,    /*!< in: level of the mutexes in the latching
 
61
        ulint   mutex_level,    /* in: level of the mutexes in the latching
92
62
                                order: this is used in the debug version */
93
63
#endif /* UNIV_SYNC_DEBUG */
94
 
        ulint   n_mutexes);     /*!< in: number of mutexes to protect the
95
 
                                hash table: must be a power of 2, or 0 */
 
64
        ulint   n_mutexes);     /* in: number of mutexes to protect the
 
65
                                hash table: must be a power of 2 */
96
66
#ifdef UNIV_SYNC_DEBUG
97
 
/** Creates a hash table.
98
 
@return         own: created table
99
 
@param n_c      in: number of array cells.  The actual number of cells is
100
 
chosen to be a slightly bigger prime number.
101
 
@param level    in: level of the mutexes in the latching order
102
 
@param n_m      in: number of mutexes to protect the hash table;
103
 
                must be a power of 2, or 0 */
104
67
# define ha_create(n_c,n_m,level) ha_create_func(n_c,level,n_m)
105
68
#else /* UNIV_SYNC_DEBUG */
106
 
/** Creates a hash table.
107
 
@return         own: created table
108
 
@param n_c      in: number of array cells.  The actual number of cells is
109
 
chosen to be a slightly bigger prime number.
110
 
@param level    in: level of the mutexes in the latching order
111
 
@param n_m      in: number of mutexes to protect the hash table;
112
 
                must be a power of 2, or 0 */
113
69
# define ha_create(n_c,n_m,level) ha_create_func(n_c,n_m)
114
70
#endif /* UNIV_SYNC_DEBUG */
115
71
 
116
 
/*************************************************************//**
 
72
/*****************************************************************
117
73
Empties a hash table and frees the memory heaps. */
118
74
UNIV_INTERN
119
75
void
120
76
ha_clear(
121
77
/*=====*/
122
 
        hash_table_t*   table); /*!< in, own: hash table */
 
78
        hash_table_t*   table); /* in, own: hash table */
123
79
 
124
 
/*************************************************************//**
 
80
/*****************************************************************
125
81
Inserts an entry into a hash table. If an entry with the same fold number
126
82
is found, its node is updated to point to the new data, and no new node
127
 
is inserted.
128
 
@return TRUE if succeed, FALSE if no more memory could be allocated */
 
83
is inserted. */
129
84
UNIV_INTERN
130
85
ibool
131
86
ha_insert_for_fold_func(
132
87
/*====================*/
133
 
        hash_table_t*   table,  /*!< in: hash table */
134
 
        ulint           fold,   /*!< in: folded value of data; if a node with
 
88
                                /* out: TRUE if succeed, FALSE if no more
 
89
                                memory could be allocated */
 
90
        hash_table_t*   table,  /* in: hash table */
 
91
        ulint           fold,   /* in: folded value of data; if a node with
135
92
                                the same fold value already exists, it is
136
93
                                updated to point to the same data, and no new
137
94
                                node is created! */
138
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
139
 
        buf_block_t*    block,  /*!< in: buffer block containing the data */
140
 
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
141
 
        void*           data);  /*!< in: data, must not be NULL */
 
95
#ifdef UNIV_DEBUG
 
96
        buf_block_t*    block,  /* in: buffer block containing the data */
 
97
#endif /* UNIV_DEBUG */
 
98
        void*           data);  /* in: data, must not be NULL */
142
99
 
143
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
144
 
/**
145
 
Inserts an entry into a hash table. If an entry with the same fold number
146
 
is found, its node is updated to point to the new data, and no new node
147
 
is inserted.
148
 
@return TRUE if succeed, FALSE if no more memory could be allocated
149
 
@param t        in: hash table
150
 
@param f        in: folded value of data
151
 
@param b        in: buffer block containing the data
152
 
@param d        in: data, must not be NULL */
 
100
#ifdef UNIV_DEBUG
153
101
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,b,d)
154
 
#else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
155
 
/**
156
 
Inserts an entry into a hash table. If an entry with the same fold number
157
 
is found, its node is updated to point to the new data, and no new node
158
 
is inserted.
159
 
@return TRUE if succeed, FALSE if no more memory could be allocated
160
 
@param t        in: hash table
161
 
@param f        in: folded value of data
162
 
@param b        ignored: buffer block containing the data
163
 
@param d        in: data, must not be NULL */
 
102
#else
164
103
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,d)
165
 
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
 
104
#endif
166
105
 
167
 
/*********************************************************//**
 
106
/*****************************************************************
 
107
Deletes an entry from a hash table. */
 
108
UNIV_INTERN
 
109
void
 
110
ha_delete(
 
111
/*======*/
 
112
        hash_table_t*   table,  /* in: hash table */
 
113
        ulint           fold,   /* in: folded value of data */
 
114
        void*           data);  /* in: data, must not be NULL and must exist
 
115
                                in the hash table */
 
116
/*************************************************************
168
117
Looks for an element when we know the pointer to the data and deletes
169
 
it from the hash table if found.
170
 
@return TRUE if found */
 
118
it from the hash table if found. */
171
119
UNIV_INLINE
172
120
ibool
173
121
ha_search_and_delete_if_found(
174
122
/*==========================*/
175
 
        hash_table_t*   table,  /*!< in: hash table */
176
 
        ulint           fold,   /*!< in: folded value of the searched data */
177
 
        void*           data);  /*!< in: pointer to the data */
178
 
#ifndef UNIV_HOTBACKUP
179
 
/*****************************************************************//**
 
123
                                /* out: TRUE if found */
 
124
        hash_table_t*   table,  /* in: hash table */
 
125
        ulint           fold,   /* in: folded value of the searched data */
 
126
        void*           data);  /* in: pointer to the data */
 
127
/*********************************************************************
180
128
Removes from the chain determined by fold all nodes whose data pointer
181
129
points to the page given. */
182
130
UNIV_INTERN
183
131
void
184
132
ha_remove_all_nodes_to_page(
185
133
/*========================*/
186
 
        hash_table_t*   table,  /*!< in: hash table */
187
 
        ulint           fold,   /*!< in: fold value */
188
 
        const page_t*   page);  /*!< in: buffer page */
189
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
190
 
/*************************************************************//**
191
 
Validates a given range of the cells in hash table.
192
 
@return TRUE if ok */
 
134
        hash_table_t*   table,  /* in: hash table */
 
135
        ulint           fold,   /* in: fold value */
 
136
        const page_t*   page);  /* in: buffer page */
 
137
/*****************************************************************
 
138
Validates a given range of the cells in hash table. */
193
139
UNIV_INTERN
194
140
ibool
195
141
ha_validate(
196
142
/*========*/
197
 
        hash_table_t*   table,          /*!< in: hash table */
198
 
        ulint           start_index,    /*!< in: start index */
199
 
        ulint           end_index);     /*!< in: end index */
200
 
#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
201
 
/*************************************************************//**
 
143
                                        /* out: TRUE if ok */
 
144
        hash_table_t*   table,          /* in: hash table */
 
145
        ulint           start_index,    /* in: start index */
 
146
        ulint           end_index);     /* in: end index */
 
147
/*****************************************************************
202
148
Prints info of a hash table. */
203
149
UNIV_INTERN
204
150
void
205
151
ha_print_info(
206
152
/*==========*/
207
 
        FILE*           file,   /*!< in: file where to print */
208
 
        hash_table_t*   table); /*!< in: hash table */
209
 
#endif /* !UNIV_HOTBACKUP */
210
 
 
211
 
/** The hash table external chain node */
 
153
        FILE*           file,   /* in: file where to print */
 
154
        hash_table_t*   table); /* in: hash table */
 
155
 
 
156
/* The hash table external chain node */
 
157
 
212
158
typedef struct ha_node_struct ha_node_t;
213
 
 
214
 
/** The hash table external chain node */
215
159
struct ha_node_struct {
216
 
        ha_node_t*      next;   /*!< next chain node or NULL if none */
217
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
218
 
        buf_block_t*    block;  /*!< buffer block containing the data, or NULL */
219
 
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
220
 
        void*           data;   /*!< pointer to the data */
221
 
        ulint           fold;   /*!< fold value for the data */
 
160
        ha_node_t*      next;   /* next chain node or NULL if none */
 
161
#ifdef UNIV_DEBUG
 
162
        buf_block_t*    block;  /* buffer block containing the data, or NULL */
 
163
#endif /* UNIV_DEBUG */
 
164
        void*           data;   /* pointer to the data */
 
165
        ulint           fold;   /* fold value for the data */
222
166
};
223
167
 
224
 
#ifndef UNIV_HOTBACKUP
225
 
/** Assert that the current thread is holding the mutex protecting a
226
 
hash bucket corresponding to a fold value.
227
 
@param table    in: hash table
228
 
@param fold     in: fold value */
229
 
# define ASSERT_HASH_MUTEX_OWN(table, fold)                             \
230
 
        ut_ad(!(table)->mutexes || mutex_own(hash_get_mutex(table, fold)))
231
 
#else /* !UNIV_HOTBACKUP */
232
 
/** Assert that the current thread is holding the mutex protecting a
233
 
hash bucket corresponding to a fold value.
234
 
@param table    in: hash table
235
 
@param fold     in: fold value */
236
 
# define ASSERT_HASH_MUTEX_OWN(table, fold) ((void) 0)
237
 
#endif /* !UNIV_HOTBACKUP */
238
 
 
239
168
#ifndef UNIV_NONINL
240
169
#include "ha0ha.ic"
241
170
#endif