2014-01-10 02:04:20 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: util.h
|
|
|
|
* Description: Misc STL string utility functions.
|
|
|
|
* Author: Samuel Charron
|
|
|
|
* Created: Mon Nov 18 2013
|
|
|
|
*
|
|
|
|
* (C) Copyright 2013, Google Inc.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef TESSERACT_TRAINING_UTIL_H_
|
|
|
|
#define TESSERACT_TRAINING_UTIL_H_
|
|
|
|
|
2018-05-20 05:52:04 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdlib>
|
2014-01-10 02:04:20 +08:00
|
|
|
#include <string>
|
2014-01-11 07:52:04 +08:00
|
|
|
#include <vector>
|
2014-01-10 02:04:20 +08:00
|
|
|
|
2017-07-20 07:42:48 +08:00
|
|
|
#include "platform.h"
|
2014-01-10 02:04:20 +08:00
|
|
|
|
|
|
|
// StringHash is the hashing functor needed by the stl hash map.
|
|
|
|
#ifndef COMPILER_MSVC
|
|
|
|
struct StringHash {
|
2018-03-03 21:36:28 +08:00
|
|
|
size_t operator()(const std::string& s) const {
|
2014-01-10 02:04:20 +08:00
|
|
|
size_t hash_code = 0;
|
|
|
|
const char* str = s.c_str();
|
|
|
|
for (int ch = 0; str[ch] != 0; ++ch) {
|
|
|
|
hash_code += str[ch] << (ch % 24);
|
|
|
|
}
|
|
|
|
return hash_code;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#else // COMPILER_MSVC
|
2018-03-03 21:36:28 +08:00
|
|
|
struct StringHash : public stdext::hash_compare <std::string> {
|
|
|
|
size_t operator()(const std::string& s) const {
|
2014-01-10 02:04:20 +08:00
|
|
|
size_t hash_code = 0;
|
|
|
|
const char* str = s.c_str();
|
|
|
|
for (int ch = 0; str[ch] != 0; ++ch) {
|
|
|
|
hash_code += str[ch] << (ch % 24);
|
|
|
|
}
|
|
|
|
return hash_code;
|
|
|
|
}
|
2018-03-03 21:36:28 +08:00
|
|
|
bool operator()(const std::string& s1, const std::string& s2) const {
|
2014-01-10 02:04:20 +08:00
|
|
|
return s1 == s2;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // !COMPILER_MSVC
|
|
|
|
|
2018-03-04 21:43:28 +08:00
|
|
|
#ifdef GOOGLE_TESSERACT
|
2014-01-10 02:04:20 +08:00
|
|
|
#include "base/heap-checker.h"
|
|
|
|
#define DISABLE_HEAP_LEAK_CHECK HeapLeakChecker::Disabler disabler
|
|
|
|
#else
|
|
|
|
#define DISABLE_HEAP_LEAK_CHECK {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // TESSERACT_TRAINING_UTIL_H_
|