1
/******************************************************
2
The hash table with external chains
4
(c) 1994-1997 Innobase Oy
6
Created 8/18/1994 Heikki Tuuri
7
*******************************************************/
14
#include "hash0hash.h"
15
#include "page0types.h"
16
#include "buf0types.h"
18
/*****************************************************************
19
Looks for an element in a hash table. */
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,
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. */
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 */
40
buf_block_t* new_block,/* in: block containing new_data */
42
void* new_data);/* in: new pointer to the data */
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)
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)
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. */
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 */
72
/*****************************************************************
73
Empties a hash table and frees the memory heaps. */
78
hash_table_t* table); /* in, own: hash table */
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
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
96
buf_block_t* block, /* in: buffer block containing the data */
97
#endif /* UNIV_DEBUG */
98
void* data); /* in: data, must not be NULL */
101
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,b,d)
103
# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,d)
106
/*****************************************************************
107
Deletes an entry from a hash table. */
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
116
/*************************************************************
117
Looks for an element when we know the pointer to the data and deletes
118
it from the hash table if found. */
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. */
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. */
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. */
153
FILE* file, /* in: file where to print */
154
hash_table_t* table); /* in: hash table */
156
/* The hash table external chain node */
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 */
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 */