641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
1 |
/*****************************************************************************
|
2 |
||
3 |
Copyright (c) 1997, 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., 59 Temple
|
|
15 |
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
*****************************************************************************/
|
|
18 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
19 |
/**************************************************//**
|
20 |
@file include/hash0hash.ic
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
21 |
The simple hash table utility
|
22 |
||
23 |
Created 5/20/1997 Heikki Tuuri
|
|
24 |
*******************************************************/
|
|
25 |
||
26 |
#include "ut0rnd.h" |
|
27 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
28 |
/************************************************************//**
|
29 |
Gets the nth cell in a hash table.
|
|
30 |
@return pointer to cell */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
31 |
UNIV_INLINE
|
32 |
hash_cell_t* |
|
33 |
hash_get_nth_cell( |
|
34 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
35 |
hash_table_t* table, /*!< in: hash table */ |
36 |
ulint n) /*!< in: cell index */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
37 |
{
|
38 |
ut_ad(n < table->n_cells); |
|
39 |
||
40 |
return(table->array + n); |
|
41 |
}
|
|
42 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
43 |
/*************************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
44 |
Clears a hash table so that all the cells become empty. */
|
45 |
UNIV_INLINE
|
|
46 |
void
|
|
47 |
hash_table_clear( |
|
48 |
/*=============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
49 |
hash_table_t* table) /*!< in/out: hash table */ |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
50 |
{
|
51 |
memset(table->array, 0x0, |
|
52 |
table->n_cells * sizeof(*table->array)); |
|
53 |
}
|
|
54 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
55 |
/*************************************************************//**
|
56 |
Returns the number of cells in a hash table.
|
|
57 |
@return number of cells */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
58 |
UNIV_INLINE
|
59 |
ulint
|
|
60 |
hash_get_n_cells( |
|
61 |
/*=============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
62 |
hash_table_t* table) /*!< in: table */ |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
63 |
{
|
64 |
return(table->n_cells); |
|
65 |
}
|
|
66 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
67 |
/**************************************************************//**
|
68 |
Calculates the hash value from a folded value.
|
|
69 |
@return hashed value */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
70 |
UNIV_INLINE
|
71 |
ulint
|
|
72 |
hash_calc_hash( |
|
73 |
/*===========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
74 |
ulint fold, /*!< in: folded value */ |
75 |
hash_table_t* table) /*!< in: hash table */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
76 |
{
|
77 |
return(ut_hash_ulint(fold, table->n_cells)); |
|
78 |
}
|
|
79 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
80 |
#ifndef UNIV_HOTBACKUP |
81 |
/************************************************************//**
|
|
82 |
Gets the mutex index for a fold value in a hash table.
|
|
83 |
@return mutex number */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
84 |
UNIV_INLINE
|
85 |
ulint
|
|
86 |
hash_get_mutex_no( |
|
87 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
88 |
hash_table_t* table, /*!< in: hash table */ |
89 |
ulint fold) /*!< in: fold */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
90 |
{
|
91 |
ut_ad(ut_is_2pow(table->n_mutexes)); |
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
92 |
return(ut_2pow_remainder(hash_calc_hash(fold, table), |
93 |
table->n_mutexes)); |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
94 |
}
|
95 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
96 |
/************************************************************//**
|
97 |
Gets the nth heap in a hash table.
|
|
98 |
@return mem heap */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
99 |
UNIV_INLINE
|
100 |
mem_heap_t* |
|
101 |
hash_get_nth_heap( |
|
102 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
103 |
hash_table_t* table, /*!< in: hash table */ |
104 |
ulint i) /*!< in: index of the heap */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
105 |
{
|
106 |
ut_ad(i < table->n_mutexes); |
|
107 |
||
108 |
return(table->heaps[i]); |
|
109 |
}
|
|
110 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
111 |
/************************************************************//**
|
112 |
Gets the heap for a fold value in a hash table.
|
|
113 |
@return mem heap */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
114 |
UNIV_INLINE
|
115 |
mem_heap_t* |
|
116 |
hash_get_heap( |
|
117 |
/*==========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
118 |
hash_table_t* table, /*!< in: hash table */ |
119 |
ulint fold) /*!< in: fold */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
120 |
{
|
121 |
ulint i; |
|
122 |
||
123 |
if (table->heap) { |
|
124 |
return(table->heap); |
|
125 |
} |
|
126 |
||
127 |
i = hash_get_mutex_no(table, fold); |
|
128 |
||
129 |
return(hash_get_nth_heap(table, i)); |
|
130 |
}
|
|
131 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
132 |
/************************************************************//**
|
133 |
Gets the nth mutex in a hash table.
|
|
134 |
@return mutex */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
135 |
UNIV_INLINE
|
136 |
mutex_t* |
|
137 |
hash_get_nth_mutex( |
|
138 |
/*===============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
139 |
hash_table_t* table, /*!< in: hash table */ |
140 |
ulint i) /*!< in: index of the mutex */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
141 |
{
|
142 |
ut_ad(i < table->n_mutexes); |
|
143 |
||
144 |
return(table->mutexes + i); |
|
145 |
}
|
|
146 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
147 |
/************************************************************//**
|
148 |
Gets the mutex for a fold value in a hash table.
|
|
149 |
@return mutex */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
150 |
UNIV_INLINE
|
151 |
mutex_t* |
|
152 |
hash_get_mutex( |
|
153 |
/*===========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
154 |
hash_table_t* table, /*!< in: hash table */ |
155 |
ulint fold) /*!< in: fold */ |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
156 |
{
|
157 |
ulint i; |
|
158 |
||
159 |
i = hash_get_mutex_no(table, fold); |
|
160 |
||
161 |
return(hash_get_nth_mutex(table, i)); |
|
162 |
}
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
163 |
#endif /* !UNIV_HOTBACKUP */ |