00001 /****************************************************** 00002 The hash table with external chains 00003 00004 (c) 1994-1997 Innobase Oy 00005 00006 Created 8/18/1994 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef ha0ha_h 00010 #define ha0ha_h 00011 00012 #include "univ.i" 00013 00014 #include "hash0hash.h" 00015 #include "page0types.h" 00016 00017 /***************************************************************** 00018 Looks for an element in a hash table. */ 00019 UNIV_INLINE 00020 void* 00021 ha_search_and_get_data( 00022 /*===================*/ 00023 /* out: pointer to the data of the first hash 00024 table node in chain having the fold number, 00025 NULL if not found */ 00026 hash_table_t* table, /* in: hash table */ 00027 ulint fold); /* in: folded value of the searched data */ 00028 /************************************************************* 00029 Looks for an element when we know the pointer to the data and updates 00030 the pointer to data if found. */ 00031 00032 void 00033 ha_search_and_update_if_found( 00034 /*==========================*/ 00035 hash_table_t* table, /* in: hash table */ 00036 ulint fold, /* in: folded value of the searched data */ 00037 void* data, /* in: pointer to the data */ 00038 void* new_data);/* in: new pointer to the data */ 00039 /***************************************************************** 00040 Creates a hash table with >= n array cells. The actual number of cells is 00041 chosen to be a prime number slightly bigger than n. */ 00042 00043 hash_table_t* 00044 ha_create( 00045 /*======*/ 00046 /* out, own: created table */ 00047 ibool in_btr_search, /* in: TRUE if the hash table is used in 00048 the btr_search module */ 00049 ulint n, /* in: number of array cells */ 00050 ulint n_mutexes, /* in: number of mutexes to protect the 00051 hash table: must be a power of 2 */ 00052 ulint mutex_level); /* in: level of the mutexes in the latching 00053 order: this is used in the debug version */ 00054 /***************************************************************** 00055 Inserts an entry into a hash table. If an entry with the same fold number 00056 is found, its node is updated to point to the new data, and no new node 00057 is inserted. */ 00058 00059 ibool 00060 ha_insert_for_fold( 00061 /*===============*/ 00062 /* out: TRUE if succeed, FALSE if no more 00063 memory could be allocated */ 00064 hash_table_t* table, /* in: hash table */ 00065 ulint fold, /* in: folded value of data; if a node with 00066 the same fold value already exists, it is 00067 updated to point to the same data, and no new 00068 node is created! */ 00069 void* data); /* in: data, must not be NULL */ 00070 /***************************************************************** 00071 Deletes an entry from a hash table. */ 00072 00073 void 00074 ha_delete( 00075 /*======*/ 00076 hash_table_t* table, /* in: hash table */ 00077 ulint fold, /* in: folded value of data */ 00078 void* data); /* in: data, must not be NULL and must exist 00079 in the hash table */ 00080 /************************************************************* 00081 Looks for an element when we know the pointer to the data and deletes 00082 it from the hash table if found. */ 00083 UNIV_INLINE 00084 ibool 00085 ha_search_and_delete_if_found( 00086 /*==========================*/ 00087 /* out: TRUE if found */ 00088 hash_table_t* table, /* in: hash table */ 00089 ulint fold, /* in: folded value of the searched data */ 00090 void* data); /* in: pointer to the data */ 00091 /********************************************************************* 00092 Removes from the chain determined by fold all nodes whose data pointer 00093 points to the page given. */ 00094 00095 void 00096 ha_remove_all_nodes_to_page( 00097 /*========================*/ 00098 hash_table_t* table, /* in: hash table */ 00099 ulint fold, /* in: fold value */ 00100 page_t* page); /* in: buffer page */ 00101 /***************************************************************** 00102 Validates a given range of the cells in hash table. */ 00103 00104 ibool 00105 ha_validate( 00106 /*========*/ 00107 /* out: TRUE if ok */ 00108 hash_table_t* table, /* in: hash table */ 00109 ulint start_index, /* in: start index */ 00110 ulint end_index); /* in: end index */ 00111 /***************************************************************** 00112 Prints info of a hash table. */ 00113 00114 void 00115 ha_print_info( 00116 /*==========*/ 00117 FILE* file, /* in: file where to print */ 00118 hash_table_t* table); /* in: hash table */ 00119 00120 /* The hash table external chain node */ 00121 00122 typedef struct ha_node_struct ha_node_t; 00123 struct ha_node_struct { 00124 ha_node_t* next; /* next chain node or NULL if none */ 00125 void* data; /* pointer to the data */ 00126 ulint fold; /* fold value for the data */ 00127 }; 00128 00129 #ifndef UNIV_NONINL 00130 #include "ha0ha.ic" 00131 #endif 00132 00133 #endif
1.4.7

