20 #ifndef TESSERACT_CCUTIL_HELPERS_H_ 
   21 #define TESSERACT_CCUTIL_HELPERS_H_ 
   44     std::hash<std::string> hasher;
 
   45     set_seed(static_cast<uint64_t>(hasher(str)));
 
   55     return range * 2.0 * 
IntRand() / INT32_MAX - range;
 
   59     return range * 
IntRand() / INT32_MAX;
 
   65     seed_ *= 6364136223846793005ULL;
 
   66     seed_ += 1442695040888963407ULL;
 
   77   int last_index = static_cast<int>(strlen(str)) - 1;
 
   78   while (last_index >= 0 &&
 
   79          (str[last_index] == 
'\n' || str[last_index] == 
'\r')) {
 
   80     str[last_index--] = 
'\0';
 
   86   if (fgetc(
file) != 
'\n') {
 
   87     fseek(
file, -1, SEEK_CUR);
 
   94 inline void Swap(T* p1, T* p2) {
 
  101 inline int RoundUp(
int n, 
int block_size) {
 
  102   return block_size * ((n + block_size - 1) / block_size);
 
  106 template <
typename T>
 
  107 inline T 
ClipToRange(
const T& x, 
const T& lower_bound, 
const T& upper_bound) {
 
  108   if (x < lower_bound) {
 
  111   if (x > upper_bound) {
 
  118 template <
typename T1, 
typename T2>
 
  120   if (x < *lower_bound) {
 
  123   if (x > *upper_bound) {
 
  129 template <
typename T1, 
typename T2>
 
  132   if (x_lo < *lower_bound) {
 
  135   if (x_hi > *upper_bound) {
 
  143 template <
typename T>
 
  144 inline void IntersectRange(
const T& lower1, 
const T& upper1, T* lower2,
 
  146   if (lower1 > *lower2) {
 
  149   if (upper1 < *upper2) {
 
  157 inline int Modulo(
int a, 
int b) {
 
  158   return (a % b + b) % b;
 
  170   return a >= 0 ? (a + b / 2) / b : (a - b / 2) / b;
 
  175   return x >= 0.0 ? static_cast<int>(x + 0.5) : -static_cast<int>(-x + 0.5);
 
  180   return x >= 0.0F ? static_cast<int>(x + 0.5F) : -static_cast<int>(-x + 0.5F);
 
  184 inline void ReverseN(
void* ptr, 
int num_bytes) {
 
  185   assert(num_bytes == 1 || num_bytes == 2 || num_bytes == 4 || num_bytes == 8);
 
  186   char* cptr = static_cast<char*>(ptr);
 
  187   int halfsize = num_bytes / 2;
 
  188   for (
int i = 0; i < halfsize; ++i) {
 
  190     cptr[i] = cptr[num_bytes - 1 - i];
 
  191     cptr[num_bytes - 1 - i] = tmp;
 
  210 #endif  // TESSERACT_CCUTIL_HELPERS_H_