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.,
15 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *****************************************************************************/
19 /**************************************************//**
20 @file include/hash0hash.ic
21 The simple hash table utility
23 Created 5/20/1997 Heikki Tuuri
24 *******************************************************/
28 /************************************************************//**
29 Gets the nth cell in a hash table.
30 @return pointer to cell */
35 hash_table_t* table, /*!< in: hash table */
36 ulint n) /*!< in: cell index */
39 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
40 ut_ad(n < table->n_cells);
42 return(table->array + n);
45 /*************************************************************//**
46 Clears a hash table so that all the cells become empty. */
51 hash_table_t* table) /*!< in/out: hash table */
54 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
55 memset(table->array, 0x0,
56 table->n_cells * sizeof(*table->array));
59 /*************************************************************//**
60 Returns the number of cells in a hash table.
61 @return number of cells */
66 hash_table_t* table) /*!< in: table */
69 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
70 return(table->n_cells);
73 /**************************************************************//**
74 Calculates the hash value from a folded value.
75 @return hashed value */
80 ulint fold, /*!< in: folded value */
81 hash_table_t* table) /*!< in: hash table */
84 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
85 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 */
96 hash_table_t* table, /*!< in: hash table */
97 ulint fold) /*!< in: fold */
100 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
101 ut_ad(ut_is_2pow(table->n_mutexes));
102 return(ut_2pow_remainder(hash_calc_hash(fold, table),
106 /************************************************************//**
107 Gets the nth heap in a hash table.
113 hash_table_t* table, /*!< in: hash table */
114 ulint i) /*!< in: index of the heap */
117 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
118 ut_ad(i < table->n_mutexes);
120 return(table->heaps[i]);
123 /************************************************************//**
124 Gets the heap for a fold value in a hash table.
130 hash_table_t* table, /*!< in: hash table */
131 ulint fold) /*!< in: fold */
136 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
142 i = hash_get_mutex_no(table, fold);
144 return(hash_get_nth_heap(table, i));
147 /************************************************************//**
148 Gets the nth mutex in a hash table.
154 hash_table_t* table, /*!< in: hash table */
155 ulint i) /*!< in: index of the mutex */
158 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
159 ut_ad(i < table->n_mutexes);
161 return(table->mutexes + i);
164 /************************************************************//**
165 Gets the mutex for a fold value in a hash table.
171 hash_table_t* table, /*!< in: hash table */
172 ulint fold) /*!< in: fold */
177 ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
179 i = hash_get_mutex_no(table, fold);
181 return(hash_get_nth_mutex(table, i));
183 #endif /* !UNIV_HOTBACKUP */