mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / hash0hash.ic
blobd246d8ee83183bfd17b1c5e42819254046c9d956
1 /******************************************************
2 The simple hash table utility
4 (c) 1997 Innobase Oy
6 Created 5/20/1997 Heikki Tuuri
7 *******************************************************/
9 #include "ut0rnd.h"
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 */
21         ut_ad(n < table->n_cells);
23         return(table->array + n);
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 */
35         return(table->n_cells);
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 */
48         return(ut_hash_ulint(fold, table->n_cells));
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 */
61         return(ut_2pow_remainder(hash_calc_hash(fold, table),
62                                  table->n_mutexes));
65 /****************************************************************
66 Gets the nth heap in a hash table. */
67 UNIV_INLINE
68 mem_heap_t*
69 hash_get_nth_heap(
70 /*==============*/
71                                 /* out: mem heap */
72         hash_table_t*   table,  /* in: hash table */
73         ulint           i)      /* in: index of the heap */
75         ut_ad(i < table->n_mutexes);
77         return(table->heaps[i]);
80 /****************************************************************
81 Gets the heap for a fold value in a hash table. */
82 UNIV_INLINE
83 mem_heap_t*
84 hash_get_heap(
85 /*==========*/
86                                 /* out: mem heap */
87         hash_table_t*   table,  /* in: hash table */
88         ulint           fold)   /* in: fold */
90         ulint   i;
92         if (table->heap) {
93                 return(table->heap);
94         }
96         i = hash_get_mutex_no(table, fold);
98         return(hash_get_nth_heap(table, i));
101 /****************************************************************
102 Gets the nth mutex in a hash table. */
103 UNIV_INLINE
104 mutex_t*
105 hash_get_nth_mutex(
106 /*===============*/
107                                 /* out: mutex */
108         hash_table_t*   table,  /* in: hash table */
109         ulint           i)      /* in: index of the mutex */
111         ut_ad(i < table->n_mutexes);
113         return(table->mutexes + i);
116 /****************************************************************
117 Gets the mutex for a fold value in a hash table. */
118 UNIV_INLINE
119 mutex_t*
120 hash_get_mutex(
121 /*===========*/
122                                 /* out: mutex */
123         hash_table_t*   table,  /* in: hash table */
124         ulint           fold)   /* in: fold */
126         ulint   i;
128         i = hash_get_mutex_no(table, fold);
130         return(hash_get_nth_mutex(table, i));