00001 /********************************************************************** 00002 Random numbers and hashing 00003 00004 (c) 1994, 1995 Innobase Oy 00005 00006 Created 1/20/1994 Heikki Tuuri 00007 ***********************************************************************/ 00008 00009 #ifndef ut0rnd_h 00010 #define ut0rnd_h 00011 00012 #include "univ.i" 00013 00014 #include "ut0byte.h" 00015 00016 /* The 'character code' for end of field or string (used 00017 in folding records */ 00018 #define UT_END_OF_FIELD 257 00019 00020 /************************************************************ 00021 This is used to set the random number seed. */ 00022 UNIV_INLINE 00023 void 00024 ut_rnd_set_seed( 00025 /*============*/ 00026 ulint seed); /* in: seed */ 00027 /************************************************************ 00028 The following function generates a series of 'random' ulint integers. */ 00029 UNIV_INLINE 00030 ulint 00031 ut_rnd_gen_next_ulint( 00032 /*==================*/ 00033 /* out: the next 'random' number */ 00034 ulint rnd); /* in: the previous random number value */ 00035 /************************************************************* 00036 The following function generates 'random' ulint integers which 00037 enumerate the value space (let there be N of them) of ulint integers 00038 in a pseudo-random fashion. Note that the same integer is repeated 00039 always after N calls to the generator. */ 00040 UNIV_INLINE 00041 ulint 00042 ut_rnd_gen_ulint(void); 00043 /*==================*/ 00044 /* out: the 'random' number */ 00045 /************************************************************ 00046 Generates a random integer from a given interval. */ 00047 UNIV_INLINE 00048 ulint 00049 ut_rnd_interval( 00050 /*============*/ 00051 /* out: the 'random' number */ 00052 ulint low, /* in: low limit; can generate also this value */ 00053 ulint high); /* in: high limit; can generate also this value */ 00054 /************************************************************* 00055 Generates a random iboolean value. */ 00056 UNIV_INLINE 00057 ibool 00058 ut_rnd_gen_ibool(void); 00059 /*=================*/ 00060 /* out: the random value */ 00061 /*********************************************************** 00062 The following function generates a hash value for a ulint integer 00063 to a hash table of size table_size, which should be a prime or some 00064 random number to work reliably. */ 00065 UNIV_INLINE 00066 ulint 00067 ut_hash_ulint( 00068 /*==========*/ 00069 /* out: hash value */ 00070 ulint key, /* in: value to be hashed */ 00071 ulint table_size); /* in: hash table size */ 00072 /***************************************************************** 00073 Folds a pair of ulints. */ 00074 UNIV_INLINE 00075 ulint 00076 ut_fold_ulint_pair( 00077 /*===============*/ 00078 /* out: folded value */ 00079 ulint n1, /* in: ulint */ 00080 ulint n2); /* in: ulint */ 00081 /***************************************************************** 00082 Folds a dulint. */ 00083 UNIV_INLINE 00084 ulint 00085 ut_fold_dulint( 00086 /*===========*/ 00087 /* out: folded value */ 00088 dulint d); /* in: dulint */ 00089 /***************************************************************** 00090 Folds a character string ending in the null character. */ 00091 UNIV_INLINE 00092 ulint 00093 ut_fold_string( 00094 /*===========*/ 00095 /* out: folded value */ 00096 const char* str); /* in: null-terminated string */ 00097 /***************************************************************** 00098 Folds a binary string. */ 00099 UNIV_INLINE 00100 ulint 00101 ut_fold_binary( 00102 /*===========*/ 00103 /* out: folded value */ 00104 const byte* str, /* in: string of bytes */ 00105 ulint len); /* in: length */ 00106 /*************************************************************** 00107 Looks for a prime number slightly greater than the given argument. 00108 The prime is chosen so that it is not near any power of 2. */ 00109 00110 ulint 00111 ut_find_prime( 00112 /*==========*/ 00113 /* out: prime */ 00114 ulint n); /* in: positive number > 100 */ 00115 00116 00117 #ifndef UNIV_NONINL 00118 #include "ut0rnd.ic" 00119 #endif 00120 00121 #endif
1.4.7

