~percona-dev/percona-innodb-plugin/percona-innodb-1.0

« back to all changes in this revision

Viewing changes to include/ha0ha.ic

  • Committer: Vadim Tkachenko
  • Date: 2008-12-01 02:05:57 UTC
  • Revision ID: vadim@percona.com-20081201020557-p7k2m94mjtdg1a83
New rw-locks

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************
 
2
The hash table with external chains
 
3
 
 
4
(c) 1994-1997 Innobase Oy
 
5
 
 
6
Created 8/18/1994 Heikki Tuuri
 
7
*************************************************************************/
 
8
 
 
9
#include "ut0rnd.h"
 
10
#include "mem0mem.h"
 
11
 
 
12
/***************************************************************
 
13
Deletes a hash node. */
 
14
UNIV_INTERN
 
15
void
 
16
ha_delete_hash_node(
 
17
/*================*/
 
18
        hash_table_t*   table,          /* in: hash table */
 
19
        ha_node_t*      del_node);      /* in: node to be deleted */
 
20
 
 
21
/**********************************************************************
 
22
Gets a hash node data. */
 
23
UNIV_INLINE
 
24
void*
 
25
ha_node_get_data(
 
26
/*=============*/
 
27
                                /* out: pointer to the data */
 
28
        ha_node_t*      node)   /* in: hash chain node */
 
29
{
 
30
        return(node->data);
 
31
}
 
32
 
 
33
/**********************************************************************
 
34
Sets hash node data. */
 
35
UNIV_INLINE
 
36
void
 
37
ha_node_set_data_func(
 
38
/*==================*/
 
39
        ha_node_t*      node,   /* in: hash chain node */
 
40
#ifdef UNIV_DEBUG
 
41
        buf_block_t*    block,  /* in: buffer block containing the data */
 
42
#endif /* UNIV_DEBUG */
 
43
        void*           data)   /* in: pointer to the data */
 
44
{
 
45
#ifdef UNIV_DEBUG
 
46
        node->block = block;
 
47
#endif /* UNIV_DEBUG */
 
48
        node->data = data;
 
49
}
 
50
 
 
51
#ifdef UNIV_DEBUG
 
52
# define ha_node_set_data(n,b,d) ha_node_set_data_func(n,b,d)
 
53
#else /* UNIV_DEBUG */
 
54
# define ha_node_set_data(n,b,d) ha_node_set_data_func(n,d)
 
55
#endif /* UNIV_DEBUG */
 
56
 
 
57
/**********************************************************************
 
58
Gets the next node in a hash chain. */
 
59
UNIV_INLINE
 
60
ha_node_t*
 
61
ha_chain_get_next(
 
62
/*==============*/
 
63
                                /* out: next node, NULL if none */
 
64
        ha_node_t*      node)   /* in: hash chain node */
 
65
{
 
66
        return(node->next);
 
67
}
 
68
 
 
69
/**********************************************************************
 
70
Gets the first node in a hash chain. */
 
71
UNIV_INLINE
 
72
ha_node_t*
 
73
ha_chain_get_first(
 
74
/*===============*/
 
75
                                /* out: first node, NULL if none */
 
76
        hash_table_t*   table,  /* in: hash table */
 
77
        ulint           fold)   /* in: fold value determining the chain */
 
78
{
 
79
        return((ha_node_t*)
 
80
               hash_get_nth_cell(table, hash_calc_hash(fold, table))->node);
 
81
}
 
82
 
 
83
/*****************************************************************
 
84
Looks for an element in a hash table. */
 
85
UNIV_INLINE
 
86
ha_node_t*
 
87
ha_search(
 
88
/*======*/
 
89
                                /* out: pointer to the first hash table node
 
90
                                in chain having the fold number, NULL if not
 
91
                                found */
 
92
        hash_table_t*   table,  /* in: hash table */
 
93
        ulint           fold)   /* in: folded value of the searched data */
 
94
{
 
95
        ha_node_t*      node;
 
96
 
 
97
        ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
 
98
 
 
99
        node = ha_chain_get_first(table, fold);
 
100
 
 
101
        while (node) {
 
102
                if (node->fold == fold) {
 
103
 
 
104
                        return(node);
 
105
                }
 
106
 
 
107
                node = ha_chain_get_next(node);
 
108
        }
 
109
 
 
110
        return(NULL);
 
111
}
 
112
 
 
113
/*****************************************************************
 
114
Looks for an element in a hash table. */
 
115
UNIV_INLINE
 
116
void*
 
117
ha_search_and_get_data(
 
118
/*===================*/
 
119
                                /* out: pointer to the data of the first hash
 
120
                                table node in chain having the fold number,
 
121
                                NULL if not found */
 
122
        hash_table_t*   table,  /* in: hash table */
 
123
        ulint           fold)   /* in: folded value of the searched data */
 
124
{
 
125
        ha_node_t*      node;
 
126
 
 
127
        ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
 
128
 
 
129
        node = ha_chain_get_first(table, fold);
 
130
 
 
131
        while (node) {
 
132
                if (node->fold == fold) {
 
133
 
 
134
                        return(node->data);
 
135
                }
 
136
 
 
137
                node = ha_chain_get_next(node);
 
138
        }
 
139
 
 
140
        return(NULL);
 
141
}
 
142
 
 
143
/*************************************************************
 
144
Looks for an element when we know the pointer to the data. */
 
145
UNIV_INLINE
 
146
ha_node_t*
 
147
ha_search_with_data(
 
148
/*================*/
 
149
                                /* out: pointer to the hash table node, NULL
 
150
                                if not found in the table */
 
151
        hash_table_t*   table,  /* in: hash table */
 
152
        ulint           fold,   /* in: folded value of the searched data */
 
153
        void*           data)   /* in: pointer to the data */
 
154
{
 
155
        ha_node_t*      node;
 
156
 
 
157
        ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
 
158
 
 
159
        node = ha_chain_get_first(table, fold);
 
160
 
 
161
        while (node) {
 
162
                if (node->data == data) {
 
163
 
 
164
                        return(node);
 
165
                }
 
166
 
 
167
                node = ha_chain_get_next(node);
 
168
        }
 
169
 
 
170
        return(NULL);
 
171
}
 
172
 
 
173
/*************************************************************
 
174
Looks for an element when we know the pointer to the data, and deletes
 
175
it from the hash table, if found. */
 
176
UNIV_INLINE
 
177
ibool
 
178
ha_search_and_delete_if_found(
 
179
/*==========================*/
 
180
                                /* out: TRUE if found */
 
181
        hash_table_t*   table,  /* in: hash table */
 
182
        ulint           fold,   /* in: folded value of the searched data */
 
183
        void*           data)   /* in: pointer to the data */
 
184
{
 
185
        ha_node_t*      node;
 
186
 
 
187
        ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
 
188
 
 
189
        node = ha_search_with_data(table, fold, data);
 
190
 
 
191
        if (node) {
 
192
                ha_delete_hash_node(table, node);
 
193
 
 
194
                return(TRUE);
 
195
        }
 
196
 
 
197
        return(FALSE);
 
198
}