~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to plugin/innobase/include/ut0ut.ic

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
4
 
 
5
This program is free software; you can redistribute it and/or modify it under
 
6
the terms of the GNU General Public License as published by the Free Software
 
7
Foundation; version 2 of the License.
 
8
 
 
9
This program is distributed in the hope that it will be useful, but WITHOUT
 
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
12
 
 
13
You should have received a copy of the GNU General Public License along with
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************************//**
 
20
@file include/ut0ut.ic
 
21
Various utilities
 
22
 
 
23
Created 5/30/1994 Heikki Tuuri
 
24
*******************************************************************/
 
25
 
 
26
/******************************************************//**
 
27
Calculates the minimum of two ulints.
 
28
@return minimum */
 
29
UNIV_INLINE
 
30
ulint
 
31
ut_min(
 
32
/*===*/
 
33
        ulint    n1,    /*!< in: first number */
 
34
        ulint    n2)    /*!< in: second number */
 
35
{
 
36
        return((n1 <= n2) ? n1 : n2);
 
37
}
 
38
 
 
39
/******************************************************//**
 
40
Calculates the maximum of two ulints.
 
41
@return maximum */
 
42
UNIV_INLINE
 
43
ulint
 
44
ut_max(
 
45
/*===*/
 
46
        ulint    n1,    /*!< in: first number */
 
47
        ulint    n2)    /*!< in: second number */
 
48
{
 
49
        return((n1 <= n2) ? n2 : n1);
 
50
}
 
51
 
 
52
/****************************************************************//**
 
53
Calculates minimum of two ulint-pairs. */
 
54
UNIV_INLINE
 
55
void
 
56
ut_pair_min(
 
57
/*========*/
 
58
        ulint*  a,      /*!< out: more significant part of minimum */
 
59
        ulint*  b,      /*!< out: less significant part of minimum */
 
60
        ulint   a1,     /*!< in: more significant part of first pair */
 
61
        ulint   b1,     /*!< in: less significant part of first pair */
 
62
        ulint   a2,     /*!< in: more significant part of second pair */
 
63
        ulint   b2)     /*!< in: less significant part of second pair */
 
64
{
 
65
        if (a1 == a2) {
 
66
                *a = a1;
 
67
                *b = ut_min(b1, b2);
 
68
        } else if (a1 < a2) {
 
69
                *a = a1;
 
70
                *b = b1;
 
71
        } else {
 
72
                *a = a2;
 
73
                *b = b2;
 
74
        }
 
75
}
 
76
 
 
77
/******************************************************//**
 
78
Compares two ulints.
 
79
@return 1 if a > b, 0 if a == b, -1 if a < b */
 
80
UNIV_INLINE
 
81
int
 
82
ut_ulint_cmp(
 
83
/*=========*/
 
84
        ulint   a,      /*!< in: ulint */
 
85
        ulint   b)      /*!< in: ulint */
 
86
{
 
87
        if (a < b) {
 
88
                return(-1);
 
89
        } else if (a == b) {
 
90
                return(0);
 
91
        } else {
 
92
                return(1);
 
93
        }
 
94
}
 
95
 
 
96
/*******************************************************//**
 
97
Compares two pairs of ulints.
 
98
@return -1 if a < b, 0 if a == b, 1 if a > b */
 
99
UNIV_INLINE
 
100
int
 
101
ut_pair_cmp(
 
102
/*========*/
 
103
        ulint   a1,     /*!< in: more significant part of first pair */
 
104
        ulint   a2,     /*!< in: less significant part of first pair */
 
105
        ulint   b1,     /*!< in: more significant part of second pair */
 
106
        ulint   b2)     /*!< in: less significant part of second pair */
 
107
{
 
108
        if (a1 > b1) {
 
109
                return(1);
 
110
        } else if (a1 < b1) {
 
111
                return(-1);
 
112
        } else if (a2 > b2) {
 
113
                return(1);
 
114
        } else if (a2 < b2) {
 
115
                return(-1);
 
116
        } else {
 
117
                return(0);
 
118
        }
 
119
}
 
120
 
 
121
/*************************************************************//**
 
122
Calculates fast the 2-logarithm of a number, rounded upward to an
 
123
integer.
 
124
@return logarithm in the base 2, rounded upward */
 
125
UNIV_INLINE
 
126
ulint
 
127
ut_2_log(
 
128
/*=====*/
 
129
        ulint   n)      /*!< in: number != 0 */
 
130
{
 
131
        ulint   res;
 
132
 
 
133
        res = 0;
 
134
 
 
135
        ut_ad(n > 0);
 
136
 
 
137
        n = n - 1;
 
138
 
 
139
        for (;;) {
 
140
                n = n / 2;
 
141
 
 
142
                if (n == 0) {
 
143
                        break;
 
144
                }
 
145
 
 
146
                res++;
 
147
        }
 
148
 
 
149
        return(res + 1);
 
150
}
 
151
 
 
152
/*************************************************************//**
 
153
Calculates 2 to power n.
 
154
@return 2 to power n */
 
155
UNIV_INLINE
 
156
ulint
 
157
ut_2_exp(
 
158
/*=====*/
 
159
        ulint   n)      /*!< in: number */
 
160
{
 
161
        return((ulint) 1 << n);
 
162
}