1 /***************************************************************************** 2 3 Copyright (c) 1994, 2021, Oracle and/or its affiliates. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, 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 Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /******************************************************************//** 28 @file include/ut0rnd.h 29 Random numbers and hashing 30 31 Created 1/20/1994 Heikki Tuuri 32 ***********************************************************************/ 33 34 #ifndef ut0rnd_h 35 #define ut0rnd_h 36 37 #include "univ.i" 38 39 #ifndef UNIV_INNOCHECKSUM 40 41 #include "ut0byte.h" 42 43 /** The 'character code' for end of field or string (used 44 in folding records */ 45 #define UT_END_OF_FIELD 257 46 47 /********************************************************//** 48 This is used to set the random number seed. */ 49 UNIV_INLINE 50 void 51 ut_rnd_set_seed( 52 /*============*/ 53 ulint seed); /*!< in: seed */ 54 /********************************************************//** 55 The following function generates a series of 'random' ulint integers. 56 @return the next 'random' number */ 57 UNIV_INLINE 58 ulint 59 ut_rnd_gen_next_ulint( 60 /*==================*/ 61 ulint rnd); /*!< in: the previous random number value */ 62 /*********************************************************//** 63 The following function generates 'random' ulint integers which 64 enumerate the value space (let there be N of them) of ulint integers 65 in a pseudo-random fashion. Note that the same integer is repeated 66 always after N calls to the generator. 67 @return the 'random' number */ 68 UNIV_INLINE 69 ulint 70 ut_rnd_gen_ulint(void); 71 /*==================*/ 72 /********************************************************//** 73 Generates a random integer from a given interval. 74 @return the 'random' number */ 75 UNIV_INLINE 76 ulint 77 ut_rnd_interval( 78 /*============*/ 79 ulint low, /*!< in: low limit; can generate also this value */ 80 ulint high); /*!< in: high limit; can generate also this value */ 81 82 /*******************************************************//** 83 The following function generates a hash value for a ulint integer 84 to a hash table of size table_size, which should be a prime or some 85 random number to work reliably. 86 @return hash value */ 87 UNIV_INLINE 88 ulint 89 ut_hash_ulint( 90 /*==========*/ 91 ulint key, /*!< in: value to be hashed */ 92 ulint table_size); /*!< in: hash table size */ 93 /*************************************************************//** 94 Folds a 64-bit integer. 95 @return folded value */ 96 UNIV_INLINE 97 ulint 98 ut_fold_ull( 99 /*========*/ 100 ib_uint64_t d) /*!< in: 64-bit integer */ 101 MY_ATTRIBUTE((const)); 102 /*************************************************************//** 103 Folds a character string ending in the null character. 104 @return folded value */ 105 UNIV_INLINE 106 ulint 107 ut_fold_string( 108 /*===========*/ 109 const char* str) /*!< in: null-terminated string */ 110 MY_ATTRIBUTE((warn_unused_result)); 111 /***********************************************************//** 112 Looks for a prime number slightly greater than the given argument. 113 The prime is chosen so that it is not near any power of 2. 114 @return prime */ 115 ulint 116 ut_find_prime( 117 /*==========*/ 118 ulint n) /*!< in: positive number > 100 */ 119 MY_ATTRIBUTE((const)); 120 121 #endif /* !UNIV_INNOCHECKSUM */ 122 123 /*************************************************************//** 124 Folds a pair of ulints. 125 @return folded value */ 126 UNIV_INLINE 127 ulint 128 ut_fold_ulint_pair( 129 /*===============*/ 130 ulint n1, /*!< in: ulint */ 131 ulint n2) /*!< in: ulint */ 132 MY_ATTRIBUTE((const)); 133 /*************************************************************//** 134 Folds a binary string. 135 @return folded value */ 136 UNIV_INLINE 137 ulint 138 ut_fold_binary( 139 /*===========*/ 140 const byte* str, /*!< in: string of bytes */ 141 ulint len) /*!< in: length */ 142 MY_ATTRIBUTE((pure)); 143 144 145 #ifndef UNIV_NONINL 146 #include "ut0rnd.ic" 147 #endif 148 149 #endif 150