mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-27 20:59:36 +08:00
Remove code that is no longer needed
The code in ccutil/hashfn.h was needed for some old compilers. Now that we support MSVC >= 2010 and compilers that has good support for C++11, we can drop this code. As a result of this file removal, we now use: std::unordered_map std::unordered_set std::unique_ptr directly in the codebase with '#include' for the needed headers.
This commit is contained in:
parent
e2ee78061a
commit
5d627aacae
@ -18,7 +18,7 @@ include_HEADERS = \
|
||||
|
||||
noinst_HEADERS = \
|
||||
ambigs.h bits16.h bitvector.h ccutil.h clst.h doubleptr.h elst2.h \
|
||||
elst.h genericheap.h globaloc.h hashfn.h indexmapbidi.h kdpair.h lsterr.h \
|
||||
elst.h genericheap.h globaloc.h indexmapbidi.h kdpair.h lsterr.h \
|
||||
nwmain.h object_cache.h qrsequence.h sorthelper.h stderr.h \
|
||||
scanutils.h tessdatamanager.h tprintf.h unicity_table.h unicodes.h \
|
||||
universalambigs.h
|
||||
|
@ -1,80 +0,0 @@
|
||||
/**********************************************************************
|
||||
* File: hashfn.h (Formerly hash.h)
|
||||
* Description: Portability hacks for hash_map, hash_set and unique_ptr.
|
||||
* Author: Ray Smith
|
||||
* Created: Wed Jan 08 14:08:25 PST 2014
|
||||
*
|
||||
* (C) Copyright 2014, 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 HASHFN_H
|
||||
#define HASHFN_H
|
||||
|
||||
#if (__cplusplus >= 201103L) || defined(_MSC_VER) // Visual Studio
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1600) // VS 2008
|
||||
#define TessHashMap std::tr1::unordered_map
|
||||
#define TessHashSet std::tr1::unordered_set
|
||||
#else // _MSC_VER
|
||||
#define TessHashMap std::unordered_map
|
||||
#define TessHashSet std::unordered_set
|
||||
#include <memory>
|
||||
#define SmartPtr std::unique_ptr
|
||||
#define HAVE_UNIQUE_PTR
|
||||
#endif // _MSC_VER
|
||||
#elif (defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ > 0)) || \
|
||||
__GNUC__ >= 4)) // gcc
|
||||
// hash_set is deprecated in gcc
|
||||
#include <ext/hash_map>
|
||||
#include <ext/hash_set>
|
||||
using __gnu_cxx::hash_map;
|
||||
using __gnu_cxx::hash_set;
|
||||
#define TessHashMap __gnu_cxx::hash_map
|
||||
#define TessHashSet __gnu_cxx::hash_set
|
||||
#else
|
||||
#include <hash_map>
|
||||
#include <hash_set>
|
||||
#define TessHashMap hash_map
|
||||
#define TessHashSet :hash_set
|
||||
#endif // gcc
|
||||
|
||||
#ifndef HAVE_UNIQUE_PTR
|
||||
// Trivial smart ptr. Expand to add features of std::unique_ptr as required.
|
||||
template<class T> class SmartPtr {
|
||||
public:
|
||||
SmartPtr() : ptr_(NULL) {}
|
||||
explicit SmartPtr(T* ptr) : ptr_(ptr) {}
|
||||
~SmartPtr() {
|
||||
delete ptr_;
|
||||
}
|
||||
|
||||
T* get() const {
|
||||
return ptr_;
|
||||
}
|
||||
void reset(T* ptr) {
|
||||
delete ptr_;
|
||||
ptr_ = ptr;
|
||||
}
|
||||
bool operator==(const T* ptr) const {
|
||||
return ptr_ == ptr;
|
||||
}
|
||||
T* operator->() const {
|
||||
return ptr_;
|
||||
}
|
||||
private:
|
||||
T* ptr_;
|
||||
};
|
||||
#endif // HAVE_UNIQUE_PTR
|
||||
|
||||
#endif // HASHFN_H
|
@ -57,9 +57,9 @@ struct RadicalStrokedHash {
|
||||
};
|
||||
|
||||
// A hash map to convert unicodes to radical,stroke pair.
|
||||
typedef TessHashMap<int, RadicalStroke> RSMap;
|
||||
typedef std::unordered_map<int, RadicalStroke> RSMap;
|
||||
// A hash map to count occurrences of each radical,stroke pair.
|
||||
typedef TessHashMap<RadicalStroke, int, RadicalStrokedHash> RSCounts;
|
||||
typedef std::unordered_map<RadicalStroke, int, RadicalStrokedHash> RSCounts;
|
||||
|
||||
// Helper function builds the RSMap from the radical-stroke file, which has
|
||||
// already been read into a STRING. Returns false on error.
|
||||
|
@ -22,7 +22,8 @@
|
||||
#ifndef TESSERACT_CCUTIL_UNICHARCOMPRESS_H_
|
||||
#define TESSERACT_CCUTIL_UNICHARCOMPRESS_H_
|
||||
|
||||
#include "hashfn.h"
|
||||
#include <unordered_map>
|
||||
|
||||
#include "serialis.h"
|
||||
#include "strngs.h"
|
||||
#include "unicharset.h"
|
||||
@ -236,17 +237,19 @@ class UnicharCompress {
|
||||
// encoder_ is the only part that is serialized. The rest is computed on load.
|
||||
GenericVector<RecodedCharID> encoder_;
|
||||
// Decoder converts the output of encoder back to a unichar-id.
|
||||
TessHashMap<RecodedCharID, int, RecodedCharID::RecodedCharIDHash> decoder_;
|
||||
std::unordered_map<RecodedCharID, int,
|
||||
RecodedCharID::RecodedCharIDHash>
|
||||
decoder_;
|
||||
// True if the index is a valid single or start code.
|
||||
GenericVector<bool> is_valid_start_;
|
||||
// Maps a prefix code to a list of valid next codes.
|
||||
// The map owns the vectors.
|
||||
TessHashMap<RecodedCharID, GenericVectorEqEq<int>*,
|
||||
std::unordered_map<RecodedCharID, GenericVectorEqEq<int>*,
|
||||
RecodedCharID::RecodedCharIDHash>
|
||||
next_codes_;
|
||||
// Maps a prefix code to a list of valid final codes.
|
||||
// The map owns the vectors.
|
||||
TessHashMap<RecodedCharID, GenericVectorEqEq<int>*,
|
||||
std::unordered_map<RecodedCharID, GenericVectorEqEq<int>*,
|
||||
RecodedCharID::RecodedCharIDHash>
|
||||
final_codes_;
|
||||
// Max of any value in encoder_ + 1.
|
||||
|
@ -1211,7 +1211,7 @@ double LSTMTrainer::ComputeCharError(const GenericVector<int>& truth_str,
|
||||
// Computes word recall error rate using a very simple bag of words algorithm.
|
||||
// NOTE that this is destructive on both input strings.
|
||||
double LSTMTrainer::ComputeWordError(STRING* truth_str, STRING* ocr_str) {
|
||||
typedef TessHashMap<std::string, int, std::hash<std::string> > StrMap;
|
||||
typedef std::unordered_map<std::string, int, std::hash<std::string> > StrMap;
|
||||
GenericVector<STRING> truth_words, ocr_words;
|
||||
truth_str->split(' ', &truth_words);
|
||||
if (truth_words.empty()) return 0.0;
|
||||
|
@ -21,9 +21,10 @@
|
||||
#ifndef TESSERACT_TEXTORD_BBGRID_H_
|
||||
#define TESSERACT_TEXTORD_BBGRID_H_
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include "clst.h"
|
||||
#include "coutln.h"
|
||||
#include "hashfn.h"
|
||||
#include "rect.h"
|
||||
#include "scrollview.h"
|
||||
|
||||
@ -364,7 +365,7 @@ template<class BBC, class BBC_CLIST, class BBC_C_IT> class GridSearch {
|
||||
// An iterator over the list at (x_, y_) in the grid_.
|
||||
BBC_C_IT it_;
|
||||
// Set of unique returned elements used when unique_mode_ is true.
|
||||
TessHashSet<BBC*, PtrHash<BBC> > returns_;
|
||||
std::unordered_set<BBC*, PtrHash<BBC> > returns_;
|
||||
};
|
||||
|
||||
// Sort function to sort a BBC by bounding_box().left().
|
||||
|
@ -46,7 +46,7 @@ const int kMinLigature = 0xfb00;
|
||||
const int kMaxLigature = 0xfb17; // Don't put the wide Hebrew letters in.
|
||||
|
||||
/* static */
|
||||
SmartPtr<LigatureTable> LigatureTable::instance_;
|
||||
std::unique_ptr<LigatureTable> LigatureTable::instance_;
|
||||
|
||||
/* static */
|
||||
LigatureTable* LigatureTable::Get() {
|
||||
|
@ -23,8 +23,9 @@
|
||||
#define TRAININGDATA_LIGATURE_TABLE_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include "hashfn.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace tesseract {
|
||||
@ -32,7 +33,7 @@ namespace tesseract {
|
||||
class PangoFontInfo; // defined in pango_font_info.h
|
||||
|
||||
// Map to substitute strings for ligatures.
|
||||
typedef TessHashMap<string, string, StringHash> LigHash;
|
||||
typedef std::unordered_map<string, string, StringHash> LigHash;
|
||||
|
||||
class LigatureTable {
|
||||
public:
|
||||
@ -61,7 +62,7 @@ class LigatureTable {
|
||||
// corresponding ligature characters.
|
||||
void Init();
|
||||
|
||||
static SmartPtr<LigatureTable> instance_;
|
||||
static std::unique_ptr<LigatureTable> instance_;
|
||||
LigHash norm_to_lig_table_;
|
||||
LigHash lig_to_norm_table_;
|
||||
int min_lig_length_;
|
||||
|
@ -688,7 +688,7 @@ void FontUtils::GetAllRenderableCharacters(const vector<string>& fonts,
|
||||
// Utilities written to be backward compatible with StringRender
|
||||
|
||||
/* static */
|
||||
int FontUtils::FontScore(const TessHashMap<char32, inT64>& ch_map,
|
||||
int FontUtils::FontScore(const std::unordered_map<char32, inT64>& ch_map,
|
||||
const string& fontname, int* raw_score,
|
||||
vector<bool>* ch_flags) {
|
||||
PangoFontInfo font_info;
|
||||
@ -704,7 +704,7 @@ int FontUtils::FontScore(const TessHashMap<char32, inT64>& ch_map,
|
||||
}
|
||||
*raw_score = 0;
|
||||
int ok_chars = 0;
|
||||
for (TessHashMap<char32, inT64>::const_iterator it = ch_map.begin();
|
||||
for (std::unordered_map<char32, inT64>::const_iterator it = ch_map.begin();
|
||||
it != ch_map.end(); ++it) {
|
||||
bool covered = (IsWhitespace(it->first) ||
|
||||
(pango_coverage_get(coverage, it->first)
|
||||
@ -722,7 +722,7 @@ int FontUtils::FontScore(const TessHashMap<char32, inT64>& ch_map,
|
||||
|
||||
|
||||
/* static */
|
||||
string FontUtils::BestFonts(const TessHashMap<char32, inT64>& ch_map,
|
||||
string FontUtils::BestFonts(const std::unordered_map<char32, inT64>& ch_map,
|
||||
vector<pair<const char*, vector<bool> > >* fonts) {
|
||||
const double kMinOKFraction = 0.99;
|
||||
// Weighted fraction of characters that must be renderable in a font to make
|
||||
|
@ -23,9 +23,9 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "commandlineflags.h"
|
||||
#include "hashfn.h"
|
||||
#include "host.h"
|
||||
#include "pango/pango-font.h"
|
||||
#include "pango/pango.h"
|
||||
@ -203,7 +203,7 @@ class FontUtils {
|
||||
// corresponding character (in order of iterating ch_map) can be rendered.
|
||||
// The return string is a list of the acceptable fonts that were used.
|
||||
static string BestFonts(
|
||||
const TessHashMap<char32, inT64>& ch_map,
|
||||
const std::unordered_map<char32, inT64>& ch_map,
|
||||
std::vector<std::pair<const char*, std::vector<bool> > >* font_flag);
|
||||
|
||||
// FontScore returns the weighted renderability score of the given
|
||||
@ -211,7 +211,7 @@ class FontUtils {
|
||||
// is also returned in raw_score.
|
||||
// The values in the bool vector ch_flags correspond to whether the
|
||||
// corresponding character (in order of iterating ch_map) can be rendered.
|
||||
static int FontScore(const TessHashMap<char32, inT64>& ch_map,
|
||||
static int FontScore(const std::unordered_map<char32, inT64>& ch_map,
|
||||
const string& fontname, int* raw_score,
|
||||
std::vector<bool>* ch_flags);
|
||||
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "hashfn.h"
|
||||
#include "host.h"
|
||||
#include "pango_font_info.h"
|
||||
#include "pango/pango-layout.h"
|
||||
@ -210,7 +210,7 @@ class StringRenderer {
|
||||
Boxa* page_boxes_;
|
||||
|
||||
// Objects cached for subsequent calls to RenderAllFontsToImage()
|
||||
TessHashMap<char32, inT64> char_map_; // Time-saving char histogram.
|
||||
std::unordered_map<char32, inT64> char_map_; // Time-saving char histogram.
|
||||
int total_chars_; // Number in the string to be rendered.
|
||||
int font_index_; // Index of next font to use in font list.
|
||||
int last_offset_; // Offset returned from last successful rendering
|
||||
|
Loading…
Reference in New Issue
Block a user