1/*****************************************************************************
2
3Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/******************************************************************//**
20@file include/ut0rnd.h
21Random numbers and hashing
22
23Created 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
36in folding records */
37#define UT_END_OF_FIELD 257
38
39/********************************************************//**
40This is used to set the random number seed. */
41UNIV_INLINE
42void
43ut_rnd_set_seed(
44/*============*/
45 ulint seed); /*!< in: seed */
46/********************************************************//**
47The following function generates a series of 'random' ulint integers.
48@return the next 'random' number */
49UNIV_INLINE
50ulint
51ut_rnd_gen_next_ulint(
52/*==================*/
53 ulint rnd); /*!< in: the previous random number value */
54/*********************************************************//**
55The following function generates 'random' ulint integers which
56enumerate the value space (let there be N of them) of ulint integers
57in a pseudo-random fashion. Note that the same integer is repeated
58always after N calls to the generator.
59@return the 'random' number */
60UNIV_INLINE
61ulint
62ut_rnd_gen_ulint(void);
63/*==================*/
64/*******************************************************//**
65The following function generates a hash value for a ulint integer
66to a hash table of size table_size, which should be a prime or some
67random number to work reliably.
68@return hash value */
69UNIV_INLINE
70ulint
71ut_hash_ulint(
72/*==========*/
73 ulint key, /*!< in: value to be hashed */
74 ulint table_size); /*!< in: hash table size */
75/*************************************************************//**
76Folds a 64-bit integer.
77@return folded value */
78UNIV_INLINE
79ulint
80ut_fold_ull(
81/*========*/
82 ib_uint64_t d) /*!< in: 64-bit integer */
83 MY_ATTRIBUTE((const));
84/*************************************************************//**
85Folds a character string ending in the null character.
86@return folded value */
87UNIV_INLINE
88ulint
89ut_fold_string(
90/*===========*/
91 const char* str) /*!< in: null-terminated string */
92 MY_ATTRIBUTE((warn_unused_result));
93/***********************************************************//**
94Looks for a prime number slightly greater than the given argument.
95The prime is chosen so that it is not near any power of 2.
96@return prime */
97ulint
98ut_find_prime(
99/*==========*/
100 ulint n) /*!< in: positive number > 100 */
101 MY_ATTRIBUTE((const));
102
103#endif /* !UNIV_INNOCHECKSUM */
104
105/*************************************************************//**
106Folds a pair of ulints.
107@return folded value */
108UNIV_INLINE
109ulint
110ut_fold_ulint_pair(
111/*===============*/
112 ulint n1, /*!< in: ulint */
113 ulint n2) /*!< in: ulint */
114 MY_ATTRIBUTE((const));
115/*************************************************************//**
116Folds a binary string.
117@return folded value */
118UNIV_INLINE
119ulint
120ut_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