1
/*****************************************************************************
3
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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
17
*****************************************************************************/
19
/******************************************************************//**
20
@file include/ut0rnd.h
1
/**********************************************************************
21
2
Random numbers and hashing
4
(c) 1994, 1995 Innobase Oy
23
6
Created 1/20/1994 Heikki Tuuri
24
7
***********************************************************************/
31
14
#include "ut0byte.h"
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
37
/********************************************************//**
20
/************************************************************
38
21
This is used to set the random number seed. */
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. */
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. */
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. */
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. */
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.
64
random number to work reliably. */
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 */
70
ulint key, /* in: value to be hashed */
71
ulint table_size); /* in: hash table size */
72
/*****************************************************************
73
Folds a pair of ulints. */
94
76
ut_fold_ulint_pair(
95
77
/*===============*/
96
ulint n1, /*!< in: ulint */
97
ulint n2) /*!< in: ulint */
98
__attribute__((const));
99
/*************************************************************//**
101
@return folded value */
78
/* out: folded value */
79
ulint n1, /* in: ulint */
80
ulint n2) /* in: ulint */
81
__attribute__((__const__));
82
/*****************************************************************
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. */
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. */
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.
112
The prime is chosen so that it is not near any power of 2. */
135
ulint n) /*!< in: positive number > 100 */
136
__attribute__((const));
118
ulint n) /* in: positive number > 100 */
119
__attribute__((__const__));
139
122
#ifndef UNIV_NONINL