~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/ut0rnd.h

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

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/ut0rnd.h
 
1
/**********************************************************************
21
2
Random numbers and hashing
22
3
 
 
4
(c) 1994, 1995 Innobase Oy
 
5
 
23
6
Created 1/20/1994 Heikki Tuuri
24
7
***********************************************************************/
25
8
 
30
13
 
31
14
#include "ut0byte.h"
32
15
 
33
 
/** The 'character code' for end of field or string (used
 
16
/* The 'character code' for end of field or string (used
34
17
in folding records */
35
18
#define UT_END_OF_FIELD         257
36
19
 
37
 
/********************************************************//**
 
20
/************************************************************
38
21
This is used to set the random number seed. */
39
22
UNIV_INLINE
40
23
void
41
24
ut_rnd_set_seed(
42
25
/*============*/
43
 
        ulint    seed);          /*!< in: seed */
44
 
/********************************************************//**
45
 
The following function generates a series of 'random' ulint integers.
46
 
@return the next 'random' number */
 
26
        ulint    seed);          /* in: seed */
 
27
/************************************************************
 
28
The following function generates a series of 'random' ulint integers. */
47
29
UNIV_INLINE
48
30
ulint
49
31
ut_rnd_gen_next_ulint(
50
32
/*==================*/
51
 
        ulint   rnd);   /*!< in: the previous random number value */
52
 
/*********************************************************//**
 
33
                        /* out: the next 'random' number */
 
34
        ulint   rnd);   /* in: the previous random number value */
 
35
/*************************************************************
53
36
The following function generates 'random' ulint integers which
54
37
enumerate the value space (let there be N of them) of ulint integers
55
38
in a pseudo-random fashion. Note that the same integer is repeated
56
 
always after N calls to the generator.
57
 
@return the 'random' number */
 
39
always after N calls to the generator. */
58
40
UNIV_INLINE
59
41
ulint
60
42
ut_rnd_gen_ulint(void);
61
43
/*==================*/
62
 
/********************************************************//**
63
 
Generates a random integer from a given interval.
64
 
@return the 'random' number */
 
44
                        /* out: the 'random' number */
 
45
/************************************************************
 
46
Generates a random integer from a given interval. */
65
47
UNIV_INLINE
66
48
ulint
67
49
ut_rnd_interval(
68
50
/*============*/
69
 
        ulint   low,    /*!< in: low limit; can generate also this value */
70
 
        ulint   high);  /*!< in: high limit; can generate also this value */
71
 
/*********************************************************//**
72
 
Generates a random iboolean value.
73
 
@return the random value */
 
51
                        /* out: the 'random' number */
 
52
        ulint   low,    /* in: low limit; can generate also this value */
 
53
        ulint   high);  /* in: high limit; can generate also this value */
 
54
/*************************************************************
 
55
Generates a random iboolean value. */
74
56
UNIV_INLINE
75
57
ibool
76
58
ut_rnd_gen_ibool(void);
77
59
/*=================*/
78
 
/*******************************************************//**
 
60
                        /* out: the random value */
 
61
/***********************************************************
79
62
The following function generates a hash value for a ulint integer
80
63
to a hash table of size table_size, which should be a prime or some
81
 
random number to work reliably.
82
 
@return hash value */
 
64
random number to work reliably. */
83
65
UNIV_INLINE
84
66
ulint
85
67
ut_hash_ulint(
86
68
/*==========*/
87
 
        ulint    key,           /*!< in: value to be hashed */
88
 
        ulint    table_size);   /*!< in: hash table size */
89
 
/*************************************************************//**
90
 
Folds a pair of ulints.
91
 
@return folded value */
 
69
                                /* out: hash value */
 
70
        ulint    key,           /* in: value to be hashed */
 
71
        ulint    table_size);   /* in: hash table size */
 
72
/*****************************************************************
 
73
Folds a pair of ulints. */
92
74
UNIV_INLINE
93
75
ulint
94
76
ut_fold_ulint_pair(
95
77
/*===============*/
96
 
        ulint   n1,     /*!< in: ulint */
97
 
        ulint   n2)     /*!< in: ulint */
98
 
        __attribute__((const));
99
 
/*************************************************************//**
100
 
Folds a dulint.
101
 
@return folded value */
 
78
                        /* out: folded value */
 
79
        ulint   n1,     /* in: ulint */
 
80
        ulint   n2)     /* in: ulint */
 
81
        __attribute__((__const__));
 
82
/*****************************************************************
 
83
Folds a dulint. */
102
84
UNIV_INLINE
103
85
ulint
104
86
ut_fold_dulint(
105
87
/*===========*/
106
 
        dulint  d)      /*!< in: dulint */
107
 
        __attribute__((const));
108
 
/*************************************************************//**
109
 
Folds a character string ending in the null character.
110
 
@return folded value */
 
88
                        /* out: folded value */
 
89
        dulint  d)      /* in: dulint */
 
90
        __attribute__((__const__));
 
91
/*****************************************************************
 
92
Folds a character string ending in the null character. */
111
93
UNIV_INLINE
112
94
ulint
113
95
ut_fold_string(
114
96
/*===========*/
115
 
        const char*     str)    /*!< in: null-terminated string */
 
97
                                /* out: folded value */
 
98
        const char*     str)    /* in: null-terminated string */
116
99
        __attribute__((pure));
117
 
/*************************************************************//**
118
 
Folds a binary string.
119
 
@return folded value */
 
100
/*****************************************************************
 
101
Folds a binary string. */
120
102
UNIV_INLINE
121
103
ulint
122
104
ut_fold_binary(
123
105
/*===========*/
124
 
        const byte*     str,    /*!< in: string of bytes */
125
 
        ulint           len)    /*!< in: length */
 
106
                                /* out: folded value */
 
107
        const byte*     str,    /* in: string of bytes */
 
108
        ulint           len)    /* in: length */
126
109
        __attribute__((pure));
127
 
/***********************************************************//**
 
110
/***************************************************************
128
111
Looks for a prime number slightly greater than the given argument.
129
 
The prime is chosen so that it is not near any power of 2.
130
 
@return prime */
 
112
The prime is chosen so that it is not near any power of 2. */
131
113
UNIV_INTERN
132
114
ulint
133
115
ut_find_prime(
134
116
/*==========*/
135
 
        ulint   n)      /*!< in: positive number > 100 */
136
 
        __attribute__((const));
 
117
                        /* out: prime */
 
118
        ulint   n)      /* in: positive number > 100 */
 
119
        __attribute__((__const__));
137
120
 
138
121
 
139
122
#ifndef UNIV_NONINL