mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innodb_plugin / include / hash0hash.ic
blob2c708cc594be4209060da6133c629b34367ae0f4
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 *******************************************************/
26 #include "ut0rnd.h"
28 /************************************************************//**
29 Gets the nth cell in a hash table.
30 @return pointer to cell */
31 UNIV_INLINE
32 hash_cell_t*
33 hash_get_nth_cell(
34 /*==============*/
35         hash_table_t*   table,  /*!< in: hash table */
36         ulint           n)      /*!< in: cell index */
38         ut_ad(table);
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. */
47 UNIV_INLINE
48 void
49 hash_table_clear(
50 /*=============*/
51         hash_table_t*   table)  /*!< in/out: hash table */
53         ut_ad(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 */
62 UNIV_INLINE
63 ulint
64 hash_get_n_cells(
65 /*=============*/
66         hash_table_t*   table)  /*!< in: table */
68         ut_ad(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 */
76 UNIV_INLINE
77 ulint
78 hash_calc_hash(
79 /*===========*/
80         ulint           fold,   /*!< in: folded value */
81         hash_table_t*   table)  /*!< in: hash table */
83         ut_ad(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 */
92 UNIV_INLINE
93 ulint
94 hash_get_mutex_no(
95 /*==============*/
96         hash_table_t*   table,  /*!< in: hash table */
97         ulint           fold)   /*!< in: fold */
99         ut_ad(table);
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),
103                                  table->n_mutexes));
106 /************************************************************//**
107 Gets the nth heap in a hash table.
108 @return mem heap */
109 UNIV_INLINE
110 mem_heap_t*
111 hash_get_nth_heap(
112 /*==============*/
113         hash_table_t*   table,  /*!< in: hash table */
114         ulint           i)      /*!< in: index of the heap */
116         ut_ad(table);
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.
125 @return mem heap */
126 UNIV_INLINE
127 mem_heap_t*
128 hash_get_heap(
129 /*==========*/
130         hash_table_t*   table,  /*!< in: hash table */
131         ulint           fold)   /*!< in: fold */
133         ulint   i;
135         ut_ad(table);
136         ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
138         if (table->heap) {
139                 return(table->heap);
140         }
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.
149 @return mutex */
150 UNIV_INLINE
151 mutex_t*
152 hash_get_nth_mutex(
153 /*===============*/
154         hash_table_t*   table,  /*!< in: hash table */
155         ulint           i)      /*!< in: index of the mutex */
157         ut_ad(table);
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.
166 @return mutex */
167 UNIV_INLINE
168 mutex_t*
169 hash_get_mutex(
170 /*===========*/
171         hash_table_t*   table,  /*!< in: hash table */
172         ulint           fold)   /*!< in: fold */
174         ulint   i;
176         ut_ad(table);
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 */