1
/*****************************************************************************
3
Copyright (C) 1997, 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/hash0hash.ic
1
/******************************************************
21
2
The simple hash table utility
23
6
Created 5/20/1997 Heikki Tuuri
24
7
*******************************************************/
28
/************************************************************//**
29
Gets the nth cell in a hash table.
30
@return pointer to cell */
11
/****************************************************************
12
Gets the nth cell in a hash table. */
35
hash_table_t* table, /*!< in: hash table */
36
ulint n) /*!< in: cell index */
17
/* out: pointer to cell */
18
hash_table_t* table, /* in: hash table */
19
ulint n) /* in: cell index */
39
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
40
21
ut_ad(n < table->n_cells);
42
23
return(table->array + n);
45
/*************************************************************//**
26
/*****************************************************************
46
27
Clears a hash table so that all the cells become empty. */
51
hash_table_t* table) /*!< in/out: hash table */
32
hash_table_t* table) /* in/out: hash table */
54
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
55
34
memset(table->array, 0x0,
56
35
table->n_cells * sizeof(*table->array));
59
/*************************************************************//**
60
Returns the number of cells in a hash table.
61
@return number of cells */
38
/*****************************************************************
39
Returns the number of cells in a hash table. */
66
hash_table_t* table) /*!< in: table */
44
/* out: number of cells */
45
hash_table_t* table) /* in: table */
69
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
70
47
return(table->n_cells);
73
/**************************************************************//**
74
Calculates the hash value from a folded value.
75
@return hashed value */
50
/******************************************************************
51
Calculates the hash value from a folded value. */
80
ulint fold, /*!< in: folded value */
81
hash_table_t* table) /*!< in: hash table */
56
/* out: hashed value */
57
ulint fold, /* in: folded value */
58
hash_table_t* table) /* in: hash table */
84
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
85
60
return(ut_hash_ulint(fold, table->n_cells));
88
#ifndef UNIV_HOTBACKUP
89
/************************************************************//**
90
Gets the mutex index for a fold value in a hash table.
91
@return mutex number */
63
/****************************************************************
64
Gets the mutex index for a fold value in a hash table. */
96
hash_table_t* table, /*!< in: hash table */
97
ulint fold) /*!< in: fold */
69
/* out: mutex number */
70
hash_table_t* table, /* in: hash table */
71
ulint fold) /* in: fold */
100
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
101
73
ut_ad(ut_is_2pow(table->n_mutexes));
102
return(ut_2pow_remainder(hash_calc_hash(fold, table),
74
return(ut_2pow_remainder(fold, table->n_mutexes));
106
/************************************************************//**
107
Gets the nth heap in a hash table.
77
/****************************************************************
78
Gets the nth heap in a hash table. */
111
81
hash_get_nth_heap(
112
82
/*==============*/
113
hash_table_t* table, /*!< in: hash table */
114
ulint i) /*!< in: index of the heap */
84
hash_table_t* table, /* in: hash table */
85
ulint i) /* in: index of the heap */
117
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
118
87
ut_ad(i < table->n_mutexes);
120
89
return(table->heaps[i]);
123
/************************************************************//**
124
Gets the heap for a fold value in a hash table.
92
/****************************************************************
93
Gets the heap for a fold value in a hash table. */
130
hash_table_t* table, /*!< in: hash table */
131
ulint fold) /*!< in: fold */
99
hash_table_t* table, /* in: hash table */
100
ulint fold) /* in: fold */
136
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
138
104
if (table->heap) {
139
105
return(table->heap);
144
110
return(hash_get_nth_heap(table, i));
147
/************************************************************//**
148
Gets the nth mutex in a hash table.
113
/****************************************************************
114
Gets the nth mutex in a hash table. */
152
117
hash_get_nth_mutex(
153
118
/*===============*/
154
hash_table_t* table, /*!< in: hash table */
155
ulint i) /*!< in: index of the mutex */
120
hash_table_t* table, /* in: hash table */
121
ulint i) /* in: index of the mutex */
158
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
159
123
ut_ad(i < table->n_mutexes);
161
125
return(table->mutexes + i);
164
/************************************************************//**
165
Gets the mutex for a fold value in a hash table.
128
/****************************************************************
129
Gets the mutex for a fold value in a hash table. */
171
hash_table_t* table, /*!< in: hash table */
172
ulint fold) /*!< in: fold */
135
hash_table_t* table, /* in: hash table */
136
ulint fold) /* in: fold */
177
ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
179
140
i = hash_get_mutex_no(table, fold);
181
142
return(hash_get_nth_mutex(table, i));
183
#endif /* !UNIV_HOTBACKUP */