~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/******************************************************
2
The simple hash table utility
3
4
(c) 1997 Innobase Oy
5
6
Created 5/20/1997 Heikki Tuuri
7
*******************************************************/
8
9
#include "ut0rnd.h"
10
11
/****************************************************************
12
Gets the nth cell in a hash table. */
13
UNIV_INLINE
14
hash_cell_t*
15
hash_get_nth_cell(
16
/*==============*/
17
				/* out: pointer to cell */
18
	hash_table_t*	table,	/* in: hash table */
19
	ulint		n)	/* in: cell index */
20
{
21
	ut_ad(n < table->n_cells);
22
23
	return(table->array + n);
24
}
25
26
/*****************************************************************
27
Returns the number of cells in a hash table. */
28
UNIV_INLINE
29
ulint
30
hash_get_n_cells(
31
/*=============*/
32
				/* out: number of cells */
33
	hash_table_t*	table)	/* in: table */
34
{
35
	return(table->n_cells);
36
}
37
38
/******************************************************************
39
Calculates the hash value from a folded value. */
40
UNIV_INLINE
41
ulint
42
hash_calc_hash(
43
/*===========*/
44
				/* out: hashed value */
45
	ulint		fold,	/* in: folded value */
46
	hash_table_t*	table)	/* in: hash table */
47
{
48
	return(ut_hash_ulint(fold, table->n_cells));
49
}
50
51
/****************************************************************
52
Gets the mutex index for a fold value in a hash table. */
53
UNIV_INLINE
54
ulint
55
hash_get_mutex_no(
56
/*==============*/
57
				/* out: mutex number */
58
	hash_table_t*	table,	/* in: hash table */
59
	ulint		fold)	/* in: fold */
60
{
61
	return(ut_2pow_remainder(fold, table->n_mutexes));
62
}
63
64
/****************************************************************
65
Gets the nth heap in a hash table. */
66
UNIV_INLINE
67
mem_heap_t*
68
hash_get_nth_heap(
69
/*==============*/
70
				/* out: mem heap */
71
	hash_table_t*	table,	/* in: hash table */
72
	ulint		i)	/* in: index of the heap */
73
{
74
	ut_ad(i < table->n_mutexes);
75
76
	return(table->heaps[i]);
77
}
78
79
/****************************************************************
80
Gets the heap for a fold value in a hash table. */
81
UNIV_INLINE
82
mem_heap_t*
83
hash_get_heap(
84
/*==========*/
85
				/* out: mem heap */
86
	hash_table_t*	table,	/* in: hash table */
87
	ulint		fold)	/* in: fold */
88
{
89
	ulint	i;
90
91
	if (table->heap) {
92
		return(table->heap);
93
	}
94
95
	i = hash_get_mutex_no(table, fold);
96
97
	return(hash_get_nth_heap(table, i));
98
}
99
100
/****************************************************************
101
Gets the nth mutex in a hash table. */
102
UNIV_INLINE
103
mutex_t*
104
hash_get_nth_mutex(
105
/*===============*/
106
				/* out: mutex */
107
	hash_table_t*	table,	/* in: hash table */
108
	ulint		i)	/* in: index of the mutex */
109
{
110
	ut_ad(i < table->n_mutexes);
111
112
	return(table->mutexes + i);
113
}
114
115
/****************************************************************
116
Gets the mutex for a fold value in a hash table. */
117
UNIV_INLINE
118
mutex_t*
119
hash_get_mutex(
120
/*===========*/
121
				/* out: mutex */
122
	hash_table_t*	table,	/* in: hash table */
123
	ulint		fold)	/* in: fold */
124
{
125
	ulint	i;
126
127
	i = hash_get_mutex_no(table, fold);
128
129
	return(hash_get_nth_mutex(table, i));
130
}