~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ha0ha.h

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

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
#ifndef ha0ha_h
 
10
#define ha0ha_h
 
11
 
 
12
#include "univ.i"
 
13
 
 
14
#include "hash0hash.h"
 
15
#include "page0types.h"
 
16
#include "buf0types.h"
 
17
 
 
18
/*****************************************************************
 
19
Looks for an element in a hash table. */
 
20
UNIV_INLINE
 
21
void*
 
22
ha_search_and_get_data(
 
23
/*===================*/
 
24
                                /* out: pointer to the data of the first hash
 
25
                                table node in chain having the fold number,
 
26
                                NULL if not found */
 
27
        hash_table_t*   table,  /* in: hash table */
 
28
        ulint           fold);  /* in: folded value of the searched data */
 
29
/*************************************************************
 
30
Looks for an element when we know the pointer to the data and updates
 
31
the pointer to data if found. */
 
32
UNIV_INTERN
 
33
void
 
34
ha_search_and_update_if_found_func(
 
35
/*===============================*/
 
36
        hash_table_t*   table,  /* in: hash table */
 
37
        ulint           fold,   /* in: folded value of the searched data */
 
38
        void*           data,   /* in: pointer to the data */
 
39
#ifdef UNIV_DEBUG
 
40
        buf_block_t*    new_block,/* in: block containing new_data */
 
41
#endif
 
42
        void*           new_data);/* in: new pointer to the data */
 
43
 
 
44
#ifdef UNIV_DEBUG
 
45
# define ha_search_and_update_if_found(table,fold,data,new_block,new_data) \
 
46
        ha_search_and_update_if_found_func(table,fold,data,new_block,new_data)
 
47
#else
 
48
# define ha_search_and_update_if_found(table,fold,data,new_block,new_data) \
 
49
        ha_search_and_update_if_found_func(table,fold,data,new_data)
 
50
#endif
 
51
/*****************************************************************
 
52
Creates a hash table with >= n array cells. The actual number of cells is
 
53
chosen to be a prime number slightly bigger than n. */
 
54
UNIV_INTERN
 
55
hash_table_t*
 
56
ha_create_func(
 
57
/*===========*/
 
58
                                /* out, own: created table */
 
59
        ulint   n,              /* in: number of array cells */
 
60
#ifdef UNIV_SYNC_DEBUG
 
61
        ulint   mutex_level,    /* in: level of the mutexes in the latching
 
62
                                order: this is used in the debug version */
 
63
#endif /* UNIV_SYNC_DEBUG */
 
64
        ulint   n_mutexes);     /* in: number of mutexes to protect the
 
65
                                hash table: must be a power of 2 */
 
66
#ifdef UNIV_SYNC_DEBUG
 
67
# define ha_create(n_c,n_m,level) ha_create_func(n_c,level,n_m)
 
68
#else /* UNIV_SYNC_DEBUG */
 
69
# define ha_create(n_c,n_m,level) ha_create_func(n_c,n_m)
 
70
#endif /* UNIV_SYNC_DEBUG */
 
71
 
 
72
/*****************************************************************
 
73
Empties a hash table and frees the memory heaps. */
 
74
UNIV_INTERN
 
75
void
 
76
ha_clear(
 
77
/*=====*/
 
78
        hash_table_t*   table); /* in, own: hash table */
 
79
 
 
80
/*****************************************************************
 
81
Inserts an entry into a hash table. If an entry with the same fold number
 
82
is found, its node is updated to point to the new data, and no new node
 
83
is inserted. */
 
84
UNIV_INTERN
 
85
ibool
 
86
ha_insert_for_fold_func(
 
87
/*====================*/
 
88
                                /* out: TRUE if succeed, FALSE if no more
 
89
                                memory could be allocated */
 
90
        hash_table_t*   table,  /* in: hash table */
 
91
        ulint           fold,   /* in: folded value of data; if a node with
 
92
                                the same fold value already exists, it is
 
93
                                updated to point to the same data, and no new
 
94
                                node is created! */
 
95
#ifdef UNIV_DEBUG
 
96
        buf_block_t*    block,  /* in: buffer block containing the data */
 
97
#endif /* UNIV_DEBUG */
 
98
        void*           data);  /* in: data, must not be NULL */
 
99
 
 
100
#ifdef UNIV_DEBUG
 
101
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,b,d)
 
102
#else
 
103
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,d)
 
104
#endif
 
105
 
 
106
/*****************************************************************
 
107
Deletes an entry from a hash table. */
 
108
UNIV_INTERN
 
109
void
 
110
ha_delete(
 
111
/*======*/
 
112
        hash_table_t*   table,  /* in: hash table */
 
113
        ulint           fold,   /* in: folded value of data */
 
114
        void*           data);  /* in: data, must not be NULL and must exist
 
115
                                in the hash table */
 
116
/*************************************************************
 
117
Looks for an element when we know the pointer to the data and deletes
 
118
it from the hash table if found. */
 
119
UNIV_INLINE
 
120
ibool
 
121
ha_search_and_delete_if_found(
 
122
/*==========================*/
 
123
                                /* out: TRUE if found */
 
124
        hash_table_t*   table,  /* in: hash table */
 
125
        ulint           fold,   /* in: folded value of the searched data */
 
126
        void*           data);  /* in: pointer to the data */
 
127
/*********************************************************************
 
128
Removes from the chain determined by fold all nodes whose data pointer
 
129
points to the page given. */
 
130
UNIV_INTERN
 
131
void
 
132
ha_remove_all_nodes_to_page(
 
133
/*========================*/
 
134
        hash_table_t*   table,  /* in: hash table */
 
135
        ulint           fold,   /* in: fold value */
 
136
        const page_t*   page);  /* in: buffer page */
 
137
/*****************************************************************
 
138
Validates a given range of the cells in hash table. */
 
139
UNIV_INTERN
 
140
ibool
 
141
ha_validate(
 
142
/*========*/
 
143
                                        /* out: TRUE if ok */
 
144
        hash_table_t*   table,          /* in: hash table */
 
145
        ulint           start_index,    /* in: start index */
 
146
        ulint           end_index);     /* in: end index */
 
147
/*****************************************************************
 
148
Prints info of a hash table. */
 
149
UNIV_INTERN
 
150
void
 
151
ha_print_info(
 
152
/*==========*/
 
153
        FILE*           file,   /* in: file where to print */
 
154
        hash_table_t*   table); /* in: hash table */
 
155
 
 
156
/* The hash table external chain node */
 
157
 
 
158
typedef struct ha_node_struct ha_node_t;
 
159
struct ha_node_struct {
 
160
        ha_node_t*      next;   /* next chain node or NULL if none */
 
161
#ifdef UNIV_DEBUG
 
162
        buf_block_t*    block;  /* buffer block containing the data, or NULL */
 
163
#endif /* UNIV_DEBUG */
 
164
        void*           data;   /* pointer to the data */
 
165
        ulint           fold;   /* fold value for the data */
 
166
};
 
167
 
 
168
#ifndef UNIV_NONINL
 
169
#include "ha0ha.ic"
 
170
#endif
 
171
 
 
172
#endif