| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 1994, 2016, 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 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 Street, Suite 500, Boston, MA 02110-1335 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 | #ifndef UNIV_INNOCHECKSUM |
| 32 | |
| 33 | #include "ut0byte.h" |
| 34 | |
| 35 | /** The 'character code' for end of field or string (used |
| 36 | in folding records */ |
| 37 | #define UT_END_OF_FIELD 257 |
| 38 | |
| 39 | /********************************************************//** |
| 40 | This is used to set the random number seed. */ |
| 41 | UNIV_INLINE |
| 42 | void |
| 43 | ut_rnd_set_seed( |
| 44 | /*============*/ |
| 45 | ulint seed); /*!< in: seed */ |
| 46 | /********************************************************//** |
| 47 | The following function generates a series of 'random' ulint integers. |
| 48 | @return the next 'random' number */ |
| 49 | UNIV_INLINE |
| 50 | ulint |
| 51 | ut_rnd_gen_next_ulint( |
| 52 | /*==================*/ |
| 53 | ulint rnd); /*!< in: the previous random number value */ |
| 54 | /*********************************************************//** |
| 55 | The following function generates 'random' ulint integers which |
| 56 | enumerate the value space (let there be N of them) of ulint integers |
| 57 | in a pseudo-random fashion. Note that the same integer is repeated |
| 58 | always after N calls to the generator. |
| 59 | @return the 'random' number */ |
| 60 | UNIV_INLINE |
| 61 | ulint |
| 62 | ut_rnd_gen_ulint(void); |
| 63 | /*==================*/ |
| 64 | /*******************************************************//** |
| 65 | The following function generates a hash value for a ulint integer |
| 66 | to a hash table of size table_size, which should be a prime or some |
| 67 | random number to work reliably. |
| 68 | @return hash value */ |
| 69 | UNIV_INLINE |
| 70 | ulint |
| 71 | ut_hash_ulint( |
| 72 | /*==========*/ |
| 73 | ulint key, /*!< in: value to be hashed */ |
| 74 | ulint table_size); /*!< in: hash table size */ |
| 75 | /*************************************************************//** |
| 76 | Folds a 64-bit integer. |
| 77 | @return folded value */ |
| 78 | UNIV_INLINE |
| 79 | ulint |
| 80 | ut_fold_ull( |
| 81 | /*========*/ |
| 82 | ib_uint64_t d) /*!< in: 64-bit integer */ |
| 83 | MY_ATTRIBUTE((const)); |
| 84 | /*************************************************************//** |
| 85 | Folds a character string ending in the null character. |
| 86 | @return folded value */ |
| 87 | UNIV_INLINE |
| 88 | ulint |
| 89 | ut_fold_string( |
| 90 | /*===========*/ |
| 91 | const char* str) /*!< in: null-terminated string */ |
| 92 | MY_ATTRIBUTE((warn_unused_result)); |
| 93 | /***********************************************************//** |
| 94 | Looks for a prime number slightly greater than the given argument. |
| 95 | The prime is chosen so that it is not near any power of 2. |
| 96 | @return prime */ |
| 97 | ulint |
| 98 | ut_find_prime( |
| 99 | /*==========*/ |
| 100 | ulint n) /*!< in: positive number > 100 */ |
| 101 | MY_ATTRIBUTE((const)); |
| 102 | |
| 103 | #endif /* !UNIV_INNOCHECKSUM */ |
| 104 | |
| 105 | /*************************************************************//** |
| 106 | Folds a pair of ulints. |
| 107 | @return folded value */ |
| 108 | UNIV_INLINE |
| 109 | ulint |
| 110 | ut_fold_ulint_pair( |
| 111 | /*===============*/ |
| 112 | ulint n1, /*!< in: ulint */ |
| 113 | ulint n2) /*!< in: ulint */ |
| 114 | MY_ATTRIBUTE((const)); |
| 115 | /*************************************************************//** |
| 116 | Folds a binary string. |
| 117 | @return folded value */ |
| 118 | UNIV_INLINE |
| 119 | ulint |
| 120 | ut_fold_binary( |
| 121 | /*===========*/ |
| 122 | const byte* str, /*!< in: string of bytes */ |
| 123 | ulint len) /*!< in: length */ |
| 124 | MY_ATTRIBUTE((pure)); |
| 125 | |
| 126 | #include "ut0rnd.ic" |
| 127 | |
| 128 | #endif |
| 129 | |