~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/hash0hash.ic

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
Clears a hash table so that all the cells become empty. */
 
28
UNIV_INLINE
 
29
void
 
30
hash_table_clear(
 
31
/*=============*/
 
32
        hash_table_t*   table)  /* in/out: hash table */
 
33
{
 
34
        memset(table->array, 0x0,
 
35
               table->n_cells * sizeof(*table->array));
 
36
}
 
37
 
 
38
/*****************************************************************
 
39
Returns the number of cells in a hash table. */
 
40
UNIV_INLINE
 
41
ulint
 
42
hash_get_n_cells(
 
43
/*=============*/
 
44
                                /* out: number of cells */
 
45
        hash_table_t*   table)  /* in: table */
 
46
{
 
47
        return(table->n_cells);
 
48
}
 
49
 
 
50
/******************************************************************
 
51
Calculates the hash value from a folded value. */
 
52
UNIV_INLINE
 
53
ulint
 
54
hash_calc_hash(
 
55
/*===========*/
 
56
                                /* out: hashed value */
 
57
        ulint           fold,   /* in: folded value */
 
58
        hash_table_t*   table)  /* in: hash table */
 
59
{
 
60
        return(ut_hash_ulint(fold, table->n_cells));
 
61
}
 
62
 
 
63
/****************************************************************
 
64
Gets the mutex index for a fold value in a hash table. */
 
65
UNIV_INLINE
 
66
ulint
 
67
hash_get_mutex_no(
 
68
/*==============*/
 
69
                                /* out: mutex number */
 
70
        hash_table_t*   table,  /* in: hash table */
 
71
        ulint           fold)   /* in: fold */
 
72
{
 
73
        ut_ad(ut_is_2pow(table->n_mutexes));
 
74
        return(ut_2pow_remainder(fold, table->n_mutexes));
 
75
}
 
76
 
 
77
/****************************************************************
 
78
Gets the nth heap in a hash table. */
 
79
UNIV_INLINE
 
80
mem_heap_t*
 
81
hash_get_nth_heap(
 
82
/*==============*/
 
83
                                /* out: mem heap */
 
84
        hash_table_t*   table,  /* in: hash table */
 
85
        ulint           i)      /* in: index of the heap */
 
86
{
 
87
        ut_ad(i < table->n_mutexes);
 
88
 
 
89
        return(table->heaps[i]);
 
90
}
 
91
 
 
92
/****************************************************************
 
93
Gets the heap for a fold value in a hash table. */
 
94
UNIV_INLINE
 
95
mem_heap_t*
 
96
hash_get_heap(
 
97
/*==========*/
 
98
                                /* out: mem heap */
 
99
        hash_table_t*   table,  /* in: hash table */
 
100
        ulint           fold)   /* in: fold */
 
101
{
 
102
        ulint   i;
 
103
 
 
104
        if (table->heap) {
 
105
                return(table->heap);
 
106
        }
 
107
 
 
108
        i = hash_get_mutex_no(table, fold);
 
109
 
 
110
        return(hash_get_nth_heap(table, i));
 
111
}
 
112
 
 
113
/****************************************************************
 
114
Gets the nth mutex in a hash table. */
 
115
UNIV_INLINE
 
116
mutex_t*
 
117
hash_get_nth_mutex(
 
118
/*===============*/
 
119
                                /* out: mutex */
 
120
        hash_table_t*   table,  /* in: hash table */
 
121
        ulint           i)      /* in: index of the mutex */
 
122
{
 
123
        ut_ad(i < table->n_mutexes);
 
124
 
 
125
        return(table->mutexes + i);
 
126
}
 
127
 
 
128
/****************************************************************
 
129
Gets the mutex for a fold value in a hash table. */
 
130
UNIV_INLINE
 
131
mutex_t*
 
132
hash_get_mutex(
 
133
/*===========*/
 
134
                                /* out: mutex */
 
135
        hash_table_t*   table,  /* in: hash table */
 
136
        ulint           fold)   /* in: fold */
 
137
{
 
138
        ulint   i;
 
139
 
 
140
        i = hash_get_mutex_no(table, fold);
 
141
 
 
142
        return(hash_get_nth_mutex(table, i));
 
143
}