~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
/*****************************************************************
25
25
Creates a hash table with >= n array cells. The actual number
26
26
of cells is chosen to be a prime number slightly bigger than n. */
27
 
 
 
27
UNIV_INTERN
28
28
hash_table_t*
29
29
hash_create(
30
30
/*========*/
32
32
        ulint   n);     /* in: number of array cells */
33
33
/*****************************************************************
34
34
Creates a mutex array to protect a hash table. */
35
 
 
 
35
UNIV_INTERN
36
36
void
37
37
hash_create_mutexes_func(
38
38
/*=====================*/
50
50
 
51
51
/*****************************************************************
52
52
Frees a hash table. */
53
 
 
 
53
UNIV_INTERN
54
54
void
55
55
hash_table_free(
56
56
/*============*/
101
101
        }\
102
102
} while (0)
103
103
 
 
104
#ifdef UNIV_HASH_DEBUG
 
105
# define HASH_ASSERT_VALID(DATA) ut_a((void*) (DATA) != (void*) -1)
 
106
# define HASH_INVALIDATE(DATA, NAME) DATA->NAME = (void*) -1
 
107
#else
 
108
# define HASH_ASSERT_VALID(DATA) do {} while (0)
 
109
# define HASH_INVALIDATE(DATA, NAME) do {} while (0)
 
110
#endif
 
111
 
104
112
/***********************************************************************
105
113
Deletes a struct from a hash table. */
106
114
 
114
122
        cell3333 = hash_get_nth_cell(TABLE, hash_calc_hash(FOLD, TABLE));\
115
123
\
116
124
        if (cell3333->node == DATA) {\
 
125
                HASH_ASSERT_VALID(DATA->NAME);\
117
126
                cell3333->node = DATA->NAME;\
118
127
        } else {\
119
128
                struct3333 = cell3333->node;\
126
135
\
127
136
                struct3333->NAME = DATA->NAME;\
128
137
        }\
 
138
        HASH_INVALIDATE(DATA, NAME);\
129
139
} while (0)
130
140
 
131
141
/***********************************************************************
141
151
 
142
152
/************************************************************************
143
153
Looks for a struct in a hash table. */
144
 
#define HASH_SEARCH(NAME, TABLE, FOLD, DATA, TEST)\
 
154
#define HASH_SEARCH(NAME, TABLE, FOLD, TYPE, DATA, TEST)\
145
155
{\
146
156
\
147
157
        HASH_ASSERT_OWNED(TABLE, FOLD)\
148
158
\
149
 
        (DATA) = HASH_GET_FIRST(TABLE, hash_calc_hash(FOLD, TABLE));\
 
159
        (DATA) = (TYPE) HASH_GET_FIRST(TABLE, hash_calc_hash(FOLD, TABLE));\
 
160
        HASH_ASSERT_VALID(DATA);\
150
161
\
151
162
        while ((DATA) != NULL) {\
152
163
                if (TEST) {\
153
164
                        break;\
154
165
                } else {\
155
 
                        (DATA) = HASH_GET_NEXT(NAME, DATA);\
 
166
                        HASH_ASSERT_VALID(HASH_GET_NEXT(NAME, DATA));\
 
167
                        (DATA) = (TYPE) HASH_GET_NEXT(NAME, DATA);\
156
168
                }\
157
169
        }\
158
170
}
166
178
                                /* out: pointer to cell */
167
179
        hash_table_t*   table,  /* in: hash table */
168
180
        ulint           n);     /* in: cell index */
 
181
 
 
182
/*****************************************************************
 
183
Clears a hash table so that all the cells become empty. */
 
184
UNIV_INLINE
 
185
void
 
186
hash_table_clear(
 
187
/*=============*/
 
188
        hash_table_t*   table); /* in/out: hash table */
 
189
 
169
190
/*****************************************************************
170
191
Returns the number of cells in a hash table. */
171
192
UNIV_INLINE
306
327
        ulint           fold);  /* in: fold */
307
328
/****************************************************************
308
329
Reserves the mutex for a fold value in a hash table. */
309
 
 
 
330
UNIV_INTERN
310
331
void
311
332
hash_mutex_enter(
312
333
/*=============*/
314
335
        ulint           fold);  /* in: fold */
315
336
/****************************************************************
316
337
Releases the mutex for a fold value in a hash table. */
317
 
 
 
338
UNIV_INTERN
318
339
void
319
340
hash_mutex_exit(
320
341
/*============*/
322
343
        ulint           fold);  /* in: fold */
323
344
/****************************************************************
324
345
Reserves all the mutexes of a hash table, in an ascending order. */
325
 
 
 
346
UNIV_INTERN
326
347
void
327
348
hash_mutex_enter_all(
328
349
/*=================*/
329
350
        hash_table_t*   table); /* in: hash table */
330
351
/****************************************************************
331
352
Releases all the mutexes of a hash table. */
332
 
 
 
353
UNIV_INTERN
333
354
void
334
355
hash_mutex_exit_all(
335
356
/*================*/
342
363
 
343
364
/* The hash table structure */
344
365
struct hash_table_struct {
 
366
#ifdef UNIV_DEBUG
345
367
        ibool           adaptive;/* TRUE if this is the hash table of the
346
368
                                adaptive hash index */
 
369
#endif /* UNIV_DEBUG */
347
370
        ulint           n_cells;/* number of cells in the hash table */
348
371
        hash_cell_t*    array;  /* pointer to cell array */
349
372
        ulint           n_mutexes;/* if mutexes != NULL, then the number of