~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0ut.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
Various utilities
 
3
 
 
4
(c) 1994, 1995 Innobase Oy
 
5
 
 
6
Created 5/30/1994 Heikki Tuuri
 
7
*******************************************************************/
 
8
 
 
9
/**********************************************************
 
10
Calculates the minimum of two ulints. */
 
11
UNIV_INLINE
 
12
ulint
 
13
ut_min(
 
14
/*===*/
 
15
                        /* out: minimum */
 
16
        ulint    n1,    /* in: first number */
 
17
        ulint    n2)    /* in: second number */
 
18
{
 
19
        return((n1 <= n2) ? n1 : n2);
 
20
}
 
21
 
 
22
/**********************************************************
 
23
Calculates the maximum of two ulints. */
 
24
UNIV_INLINE
 
25
ulint
 
26
ut_max(
 
27
/*===*/
 
28
                        /* out: maximum */
 
29
        ulint    n1,    /* in: first number */
 
30
        ulint    n2)    /* in: second number */
 
31
{
 
32
        return((n1 <= n2) ? n2 : n1);
 
33
}
 
34
 
 
35
/********************************************************************
 
36
Calculates minimum of two ulint-pairs. */
 
37
UNIV_INLINE
 
38
void
 
39
ut_pair_min(
 
40
/*========*/
 
41
        ulint*  a,      /* out: more significant part of minimum */
 
42
        ulint*  b,      /* out: less significant part of minimum */
 
43
        ulint   a1,     /* in: more significant part of first pair */
 
44
        ulint   b1,     /* in: less significant part of first pair */
 
45
        ulint   a2,     /* in: more significant part of second pair */
 
46
        ulint   b2)     /* in: less significant part of second pair */
 
47
{
 
48
        if (a1 == a2) {
 
49
                *a = a1;
 
50
                *b = ut_min(b1, b2);
 
51
        } else if (a1 < a2) {
 
52
                *a = a1;
 
53
                *b = b1;
 
54
        } else {
 
55
                *a = a2;
 
56
                *b = b2;
 
57
        }
 
58
}
 
59
 
 
60
/**********************************************************
 
61
Compares two ulints. */
 
62
UNIV_INLINE
 
63
int
 
64
ut_ulint_cmp(
 
65
/*=========*/
 
66
                        /* out: 1 if a > b, 0 if a == b, -1 if a < b */
 
67
        ulint   a,      /* in: ulint */
 
68
        ulint   b)      /* in: ulint */
 
69
{
 
70
        if (a < b) {
 
71
                return(-1);
 
72
        } else if (a == b) {
 
73
                return(0);
 
74
        } else {
 
75
                return(1);
 
76
        }
 
77
}
 
78
 
 
79
/***********************************************************
 
80
Compares two pairs of ulints. */
 
81
UNIV_INLINE
 
82
int
 
83
ut_pair_cmp(
 
84
/*========*/
 
85
                        /* out: -1 if a < b, 0 if a == b, 1 if a > b */
 
86
        ulint   a1,     /* in: more significant part of first pair */
 
87
        ulint   a2,     /* in: less significant part of first pair */
 
88
        ulint   b1,     /* in: more significant part of second pair */
 
89
        ulint   b2)     /* in: less significant part of second pair */
 
90
{
 
91
        if (a1 > b1) {
 
92
                return(1);
 
93
        } else if (a1 < b1) {
 
94
                return(-1);
 
95
        } else if (a2 > b2) {
 
96
                return(1);
 
97
        } else if (a2 < b2) {
 
98
                return(-1);
 
99
        } else {
 
100
                return(0);
 
101
        }
 
102
}
 
103
 
 
104
/*****************************************************************
 
105
Calculates fast the 2-logarithm of a number, rounded upward to an
 
106
integer. */
 
107
UNIV_INLINE
 
108
ulint
 
109
ut_2_log(
 
110
/*=====*/
 
111
                        /* out: logarithm in the base 2, rounded upward */
 
112
        ulint   n)      /* in: number != 0 */
 
113
{
 
114
        ulint   res;
 
115
 
 
116
        res = 0;
 
117
 
 
118
        ut_ad(n > 0);
 
119
 
 
120
        n = n - 1;
 
121
 
 
122
        for (;;) {
 
123
                n = n / 2;
 
124
 
 
125
                if (n == 0) {
 
126
                        break;
 
127
                }
 
128
 
 
129
                res++;
 
130
        }
 
131
 
 
132
        return(res + 1);
 
133
}
 
134
 
 
135
/*****************************************************************
 
136
Calculates 2 to power n. */
 
137
UNIV_INLINE
 
138
ulint
 
139
ut_2_exp(
 
140
/*=====*/
 
141
                        /* out: 2 to power n */
 
142
        ulint   n)      /* in: number */
 
143
{
 
144
        return((ulint) 1 << n);
 
145
}