mariadb/innobase/include/ha0ha.ic
unknown 1065f2bbd6 Merge with 4.0
innobase/dict/dict0boot.c:
  Auto merged
innobase/dict/dict0load.c:
  Auto merged
innobase/dict/dict0mem.c:
  Auto merged
innobase/fut/fut0lst.c:
  Auto merged
innobase/include/buf0lru.h:
  Auto merged
innobase/include/dict0mem.h:
  Auto merged
innobase/include/fsp0fsp.h:
  Auto merged
innobase/include/ha0ha.h:
  Auto merged
innobase/include/ibuf0ibuf.h:
  Auto merged
innobase/include/lock0lock.h:
  Auto merged
innobase/include/log0log.h:
  Auto merged
innobase/include/mem0pool.h:
  Auto merged
innobase/include/mtr0mtr.h:
  Auto merged
innobase/include/os0file.h:
  Auto merged
innobase/include/rem0rec.h:
  Auto merged
innobase/include/rem0rec.ic:
  Auto merged
innobase/include/srv0srv.h:
  Auto merged
innobase/include/sync0sync.h:
  Auto merged
innobase/include/trx0sys.h:
  Auto merged
innobase/include/ut0byte.h:
  Auto merged
innobase/include/ut0ut.h:
  Auto merged
innobase/mem/mem0pool.c:
  Auto merged
innobase/mtr/mtr0mtr.c:
  Auto merged
innobase/os/os0proc.c:
  Auto merged
innobase/pars/lexyy.c:
  Auto merged
innobase/pars/pars0opt.c:
  Auto merged
innobase/row/row0ins.c:
  Auto merged
innobase/row/row0purge.c:
  Auto merged
innobase/row/row0uins.c:
  Auto merged
innobase/row/row0umod.c:
  Auto merged
innobase/row/row0undo.c:
  Auto merged
innobase/row/row0upd.c:
  Auto merged
innobase/trx/trx0purge.c:
  Auto merged
innobase/trx/trx0roll.c:
  Auto merged
innobase/trx/trx0sys.c:
  Auto merged
innobase/trx/trx0undo.c:
  Auto merged
innobase/ut/ut0byte.c:
  Auto merged
pstack/bucomm.h:
  Auto merged
pstack/budbg.h:
  Auto merged
sql/item_sum.h:
  Auto merged
sql/slave.cc:
  Auto merged
sql/sql_db.cc:
  Auto merged
support-files/mysql.spec.sh:
  Auto merged
tests/insert_test.c:
  Auto merged
mysql-test/t/func_group.test:
  Merge with 4.0
  Put 4.1 tests lasts
sql/ha_innodb.cc:
  Merge with 4.0
  Added checking of results from my_malloc()
BitKeeper/etc/logging_ok:
  Logging to logging@openlogging.org accepted
2004-04-26 15:53:31 +03:00

220 lines
5.1 KiB
Text

/************************************************************************
The hash table with external chains
(c) 1994-1997 Innobase Oy
Created 8/18/1994 Heikki Tuuri
*************************************************************************/
#include "ut0rnd.h"
#include "mem0mem.h"
/***************************************************************
Deletes a hash node. */
void
ha_delete_hash_node(
/*================*/
hash_table_t* table, /* in: hash table */
ha_node_t* del_node); /* in: node to be deleted */
/**********************************************************************
Gets a hash node data. */
UNIV_INLINE
void*
ha_node_get_data(
/*=============*/
/* out: pointer to the data */
ha_node_t* node) /* in: hash chain node */
{
return(node->data);
}
/**********************************************************************
Sets hash node data. */
UNIV_INLINE
void
ha_node_set_data(
/*=============*/
ha_node_t* node, /* in: hash chain node */
void* data) /* in: pointer to the data */
{
node->data = data;
}
/**********************************************************************
Gets the next node in a hash chain. */
UNIV_INLINE
ha_node_t*
ha_chain_get_next(
/*==============*/
/* out: next node, NULL if none */
ha_node_t* node) /* in: hash chain node */
{
return(node->next);
}
/**********************************************************************
Gets the first node in a hash chain. */
UNIV_INLINE
ha_node_t*
ha_chain_get_first(
/*===============*/
/* out: first node, NULL if none */
hash_table_t* table, /* in: hash table */
ulint fold) /* in: fold value determining the chain */
{
return(hash_get_nth_cell(table, hash_calc_hash(fold, table))->node);
}
/*****************************************************************
Looks for an element in a hash table. */
UNIV_INLINE
ha_node_t*
ha_search(
/*======*/
/* out: pointer to the first hash table node
in chain having the fold number, NULL if not
found */
hash_table_t* table, /* in: hash table */
ulint fold) /* in: folded value of the searched data */
{
ha_node_t* node;
#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
#endif /* UNIV_SYNC_DEBUG */
node = ha_chain_get_first(table, fold);
while (node) {
if (node->fold == fold) {
return(node);
}
node = ha_chain_get_next(node);
}
return(NULL);
}
/*****************************************************************
Looks for an element in a hash table. */
UNIV_INLINE
void*
ha_search_and_get_data(
/*===================*/
/* out: pointer to the data of the first hash
table node in chain having the fold number,
NULL if not found */
hash_table_t* table, /* in: hash table */
ulint fold) /* in: folded value of the searched data */
{
ha_node_t* node;
#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
#endif /* UNIV_SYNC_DEBUG */
node = ha_chain_get_first(table, fold);
while (node) {
if (node->fold == fold) {
return(node->data);
}
node = ha_chain_get_next(node);
}
return(NULL);
}
/*************************************************************
Looks for an element when we know the pointer to the data. */
UNIV_INLINE
ha_node_t*
ha_search_with_data(
/*================*/
/* out: pointer to the hash table node, NULL
if not found in the table */
hash_table_t* table, /* in: hash table */
ulint fold, /* in: folded value of the searched data */
void* data) /* in: pointer to the data */
{
ha_node_t* node;
#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
#endif /* UNIV_SYNC_DEBUG */
node = ha_chain_get_first(table, fold);
while (node) {
if (node->data == data) {
return(node);
}
node = ha_chain_get_next(node);
}
return(NULL);
}
/*************************************************************
Looks for an element when we know the pointer to the data, and deletes
it from the hash table, if found. */
UNIV_INLINE
ibool
ha_search_and_delete_if_found(
/*==========================*/
/* out: TRUE if found */
hash_table_t* table, /* in: hash table */
ulint fold, /* in: folded value of the searched data */
void* data) /* in: pointer to the data */
{
ha_node_t* node;
#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
#endif /* UNIV_SYNC_DEBUG */
node = ha_search_with_data(table, fold, data);
if (node) {
ha_delete_hash_node(table, node);
return(TRUE);
}
return(FALSE);
}
/*****************************************************************
Reserves the necessary hash table mutex and inserts an entry into the hash
table. */
UNIV_INLINE
ibool
ha_insert_for_fold_mutex(
/*=====================*/
/* out: TRUE if succeed, FALSE if no more
memory could be allocated */
hash_table_t* table, /* in: hash table */
ulint fold, /* in: folded value of data; if a node with
the same fold value already exists, it is
updated to point to the same data, and no new
node is created! */
void* data) /* in: data, must not be NULL */
{
ibool ret;
hash_mutex_enter(table, fold);
ret = ha_insert_for_fold(table, fold, data);
hash_mutex_exit(table, fold);
return(ret);
}