MySQL  8.0.20
Source Code Documentation
ut0rnd.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2018, Oracle and/or its affiliates. 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, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/ut0rnd.h
28  Random numbers and hashing
29 
30  Created 1/20/1994 Heikki Tuuri
31  ***********************************************************************/
32 
33 #ifndef ut0rnd_h
34 #define ut0rnd_h
35 
36 #include "univ.i"
37 #include "ut0byte.h"
38 
39 /** The 'character code' for end of field or string (used
40 in folding records */
41 #define UT_END_OF_FIELD 257
42 
43 /** The following function generates a series of 'random' ulint integers.
44  @return the next 'random' number */
45 UNIV_INLINE
47  ulint rnd); /*!< in: the previous random number value */
48 /** The following function generates 'random' ulint integers which
49  enumerate the value space (let there be N of them) of ulint integers
50  in a pseudo-random fashion. Note that the same integer is repeated
51  always after N calls to the generator.
52  @return the 'random' number */
53 UNIV_INLINE
54 ulint ut_rnd_gen_ulint(void);
55 
56 /** Generates a random integer from a given interval.
57 @param[in] low low limit; can generate also this value
58 @param[in] high high limit; can generate also this value
59 @return the 'random' number */
60 UNIV_INLINE
61 ulint ut_rnd_interval(ulint low, ulint high);
62 
63 /** The following function generates a hash value for a ulint integer to a
64 hash table of size table_size, which should be a prime or some random number
65 to work reliably.
66 @param[in] key value to be hashed
67 @param[in] table_size hash table size
68 @return hash value */
69 UNIV_INLINE
70 ulint ut_hash_ulint(ulint key, ulint table_size);
71 
72 /** Folds a 64-bit integer.
73  @return folded value */
74 UNIV_INLINE
75 ulint ut_fold_ull(ib_uint64_t d) /*!< in: 64-bit integer */
76  MY_ATTRIBUTE((const));
77 /** Folds a character string ending in the null character.
78  @return folded value */
79 UNIV_INLINE
80 ulint ut_fold_string(const char *str) /*!< in: null-terminated string */
81  MY_ATTRIBUTE((warn_unused_result));
82 /** Looks for a prime number slightly greater than the given argument.
83  The prime is chosen so that it is not near any power of 2.
84  @return prime */
85 ulint ut_find_prime(ulint n) /*!< in: positive number > 100 */
86  MY_ATTRIBUTE((const));
87 
88 /** Folds a pair of ulints.
89  @return folded value */
90 UNIV_INLINE
91 ulint ut_fold_ulint_pair(ulint n1, /*!< in: ulint */
92  ulint n2) /*!< in: ulint */
93  MY_ATTRIBUTE((const));
94 /** Folds a binary string.
95  @return folded value */
96 UNIV_INLINE
97 ulint ut_fold_binary(const byte *str, /*!< in: string of bytes */
98  ulint len) /*!< in: length */
99  MY_ATTRIBUTE((pure));
100 
101 #include "ut0rnd.ic"
102 
103 #endif
UNIV_INLINE ulint ut_hash_ulint(ulint key, ulint table_size)
The following function generates a hash value for a ulint integer to a hash table of size table_size...
UNIV_INLINE ulint ut_rnd_interval(ulint low, ulint high)
Generates a random integer from a given interval.
UNIV_INLINE ulint ut_fold_ull(ib_uint64_t d)
Folds a 64-bit integer.
UNIV_INLINE ulint ut_fold_binary(const byte *str, ulint len)
Folds a binary string.
#define rnd(X)
Definition: mi_test3.cc:39
UNIV_INLINE ulint ut_rnd_gen_next_ulint(ulint rnd)
The following function generates a series of &#39;random&#39; ulint integers.
ulint ut_find_prime(ulint n)
Looks for a prime number slightly greater than the given argument.
Definition: ut0rnd.cc:47
UNIV_INLINE ulint ut_rnd_gen_ulint(void)
The following function generates &#39;random&#39; ulint integers which enumerate the value space (let there b...
UNIV_INLINE ulint ut_fold_string(const char *str)
Folds a character string ending in the null character.
Definition: innodb_utility.cc:61
Utilities for byte operations.
static const char * key
Definition: suite_stubs.c:14
int n
Definition: xcom_base.c:425
UNIV_INLINE ulint ut_fold_ulint_pair(ulint n1, ulint n2)
Folds a pair of ulints.
unsigned char byte
Blob class.
Definition: common.h:159