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., 15 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 17 *****************************************************************************/ 18 19 /******************************************************************//** 20 @file include/ut0rnd.h 21 Random numbers and hashing 22 23 Created 1/20/1994 Heikki Tuuri 24 ***********************************************************************/ 25 26 #ifndef ut0rnd_h 27 #define ut0rnd_h 28 29 #include "univ.i" 30 31 #include "ut0byte.h" 32 33 /** The 'character code' for end of field or string (used 34 in folding records */ 35 #define UT_END_OF_FIELD 257 36 37 /********************************************************//** 38 This is used to set the random number seed. */ 39 UNIV_INLINE 40 void 41 ut_rnd_set_seed( 42 /*============*/ 43 ulint seed); /*!< in: seed */ 44 /********************************************************//** 45 The following function generates a series of 'random' ulint integers. 46 @return the next 'random' number */ 47 UNIV_INLINE 48 ulint 49 ut_rnd_gen_next_ulint( 50 /*==================*/ 51 ulint rnd); /*!< in: the previous random number value */ 52 /*********************************************************//** 53 The following function generates 'random' ulint integers which 54 enumerate the value space (let there be N of them) of ulint integers 55 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 */ 58 UNIV_INLINE 59 ulint 60 ut_rnd_gen_ulint(void); 61 /*==================*/ 62 /********************************************************//** 63 Generates a random integer from a given interval. 64 @return the 'random' number */ 65 UNIV_INLINE 66 ulint 67 ut_rnd_interval( 68 /*============*/ 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 */ 74 UNIV_INLINE 75 ibool 76 ut_rnd_gen_ibool(void); 77 /*=================*/ 78 /*******************************************************//** 79 The following function generates a hash value for a ulint integer 80 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 */ 83 UNIV_INLINE 84 ulint 85 ut_hash_ulint( 86 /*==========*/ 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 */ 92 UNIV_INLINE 93 ulint 94 ut_fold_ulint_pair( 95 /*===============*/ 96 ulint n1, /*!< in: ulint */ 97 ulint n2) /*!< in: ulint */ 98 __attribute__((const)); 99 /*************************************************************//** 100 Folds a 64-bit integer. 101 @return folded value */ 102 UNIV_INLINE 103 ulint 104 ut_fold_ull( 105 /*========*/ 106 ib_uint64_t d) /*!< in: 64-bit integer */ 107 __attribute__((const)); 108 /*************************************************************//** 109 Folds a character string ending in the null character. 110 @return folded value */ 111 UNIV_INLINE 112 ulint 113 ut_fold_string( 114 /*===========*/ 115 const char* str) /*!< in: null-terminated string */ 116 __attribute__((pure)); 117 /*************************************************************//** 118 Folds a binary string. 119 @return folded value */ 120 UNIV_INLINE 121 ulint 122 ut_fold_binary( 123 /*===========*/ 124 const byte* str, /*!< in: string of bytes */ 125 ulint len) /*!< in: length */ 126 __attribute__((pure)); 127 /***********************************************************//** 128 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 */ 131 UNIV_INTERN 132 ulint 133 ut_find_prime( 134 /*==========*/ 135 ulint n) /*!< in: positive number > 100 */ 136 __attribute__((const)); 137 138 139 #ifndef UNIV_NONINL 140 #include "ut0rnd.ic" 141 #endif 142 143 #endif 144