~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-02-05 09:11:16 UTC
  • Revision ID: brian@tangent.org-20090205091116-iy0ersp6bhyzt1ad
Removed dead variables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/hash0hash.ic
 
1
/******************************************************
21
2
The simple hash table utility
22
3
 
 
4
(c) 1997 Innobase Oy
 
5
 
23
6
Created 5/20/1997 Heikki Tuuri
24
7
*******************************************************/
25
8
 
26
9
#include "ut0rnd.h"
27
10
 
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. */
31
13
UNIV_INLINE
32
14
hash_cell_t*
33
15
hash_get_nth_cell(
34
16
/*==============*/
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 */
37
20
{
38
 
        ut_ad(table);
39
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
40
21
        ut_ad(n < table->n_cells);
41
22
 
42
23
        return(table->array + n);
43
24
}
44
25
 
45
 
/*************************************************************//**
 
26
/*****************************************************************
46
27
Clears a hash table so that all the cells become empty. */
47
28
UNIV_INLINE
48
29
void
49
30
hash_table_clear(
50
31
/*=============*/
51
 
        hash_table_t*   table)  /*!< in/out: hash table */
 
32
        hash_table_t*   table)  /* in/out: hash table */
52
33
{
53
 
        ut_ad(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));
57
36
}
58
37
 
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. */
62
40
UNIV_INLINE
63
41
ulint
64
42
hash_get_n_cells(
65
43
/*=============*/
66
 
        hash_table_t*   table)  /*!< in: table */
 
44
                                /* out: number of cells */
 
45
        hash_table_t*   table)  /* in: table */
67
46
{
68
 
        ut_ad(table);
69
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
70
47
        return(table->n_cells);
71
48
}
72
49
 
73
 
/**************************************************************//**
74
 
Calculates the hash value from a folded value.
75
 
@return hashed value */
 
50
/******************************************************************
 
51
Calculates the hash value from a folded value. */
76
52
UNIV_INLINE
77
53
ulint
78
54
hash_calc_hash(
79
55
/*===========*/
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 */
82
59
{
83
 
        ut_ad(table);
84
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
85
60
        return(ut_hash_ulint(fold, table->n_cells));
86
61
}
87
62
 
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. */
92
65
UNIV_INLINE
93
66
ulint
94
67
hash_get_mutex_no(
95
68
/*==============*/
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 */
98
72
{
99
 
        ut_ad(table);
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),
103
 
                                 table->n_mutexes));
 
74
        return(ut_2pow_remainder(fold, table->n_mutexes));
104
75
}
105
76
 
106
 
/************************************************************//**
107
 
Gets the nth heap in a hash table.
108
 
@return mem heap */
 
77
/****************************************************************
 
78
Gets the nth heap in a hash table. */
109
79
UNIV_INLINE
110
80
mem_heap_t*
111
81
hash_get_nth_heap(
112
82
/*==============*/
113
 
        hash_table_t*   table,  /*!< in: hash table */
114
 
        ulint           i)      /*!< in: index of the heap */
 
83
                                /* out: mem heap */
 
84
        hash_table_t*   table,  /* in: hash table */
 
85
        ulint           i)      /* in: index of the heap */
115
86
{
116
 
        ut_ad(table);
117
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
118
87
        ut_ad(i < table->n_mutexes);
119
88
 
120
89
        return(table->heaps[i]);
121
90
}
122
91
 
123
 
/************************************************************//**
124
 
Gets the heap for a fold value in a hash table.
125
 
@return mem heap */
 
92
/****************************************************************
 
93
Gets the heap for a fold value in a hash table. */
126
94
UNIV_INLINE
127
95
mem_heap_t*
128
96
hash_get_heap(
129
97
/*==========*/
130
 
        hash_table_t*   table,  /*!< in: hash table */
131
 
        ulint           fold)   /*!< in: fold */
 
98
                                /* out: mem heap */
 
99
        hash_table_t*   table,  /* in: hash table */
 
100
        ulint           fold)   /* in: fold */
132
101
{
133
102
        ulint   i;
134
103
 
135
 
        ut_ad(table);
136
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
137
 
 
138
104
        if (table->heap) {
139
105
                return(table->heap);
140
106
        }
144
110
        return(hash_get_nth_heap(table, i));
145
111
}
146
112
 
147
 
/************************************************************//**
148
 
Gets the nth mutex in a hash table.
149
 
@return mutex */
 
113
/****************************************************************
 
114
Gets the nth mutex in a hash table. */
150
115
UNIV_INLINE
151
116
mutex_t*
152
117
hash_get_nth_mutex(
153
118
/*===============*/
154
 
        hash_table_t*   table,  /*!< in: hash table */
155
 
        ulint           i)      /*!< in: index of the mutex */
 
119
                                /* out: mutex */
 
120
        hash_table_t*   table,  /* in: hash table */
 
121
        ulint           i)      /* in: index of the mutex */
156
122
{
157
 
        ut_ad(table);
158
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
159
123
        ut_ad(i < table->n_mutexes);
160
124
 
161
125
        return(table->mutexes + i);
162
126
}
163
127
 
164
 
/************************************************************//**
165
 
Gets the mutex for a fold value in a hash table.
166
 
@return mutex */
 
128
/****************************************************************
 
129
Gets the mutex for a fold value in a hash table. */
167
130
UNIV_INLINE
168
131
mutex_t*
169
132
hash_get_mutex(
170
133
/*===========*/
171
 
        hash_table_t*   table,  /*!< in: hash table */
172
 
        ulint           fold)   /*!< in: fold */
 
134
                                /* out: mutex */
 
135
        hash_table_t*   table,  /* in: hash table */
 
136
        ulint           fold)   /* in: fold */
173
137
{
174
138
        ulint   i;
175
139
 
176
 
        ut_ad(table);
177
 
        ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
178
 
 
179
140
        i = hash_get_mutex_no(table, fold);
180
141
 
181
142
        return(hash_get_nth_mutex(table, i));
182
143
}
183
 
#endif /* !UNIV_HOTBACKUP */