Skip to content

Commit 5d627aa

Browse files
committed
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.
1 parent e2ee780 commit 5d627aa

11 files changed

+27
-102
lines changed

ccutil/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include_HEADERS = \
1818

1919
noinst_HEADERS = \
2020
ambigs.h bits16.h bitvector.h ccutil.h clst.h doubleptr.h elst2.h \
21-
elst.h genericheap.h globaloc.h hashfn.h indexmapbidi.h kdpair.h lsterr.h \
21+
elst.h genericheap.h globaloc.h indexmapbidi.h kdpair.h lsterr.h \
2222
nwmain.h object_cache.h qrsequence.h sorthelper.h stderr.h \
2323
scanutils.h tessdatamanager.h tprintf.h unicity_table.h unicodes.h \
2424
universalambigs.h

ccutil/hashfn.h

-80
This file was deleted.

ccutil/unicharcompress.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ struct RadicalStrokedHash {
5757
};
5858

5959
// A hash map to convert unicodes to radical,stroke pair.
60-
typedef TessHashMap<int, RadicalStroke> RSMap;
60+
typedef std::unordered_map<int, RadicalStroke> RSMap;
6161
// A hash map to count occurrences of each radical,stroke pair.
62-
typedef TessHashMap<RadicalStroke, int, RadicalStrokedHash> RSCounts;
62+
typedef std::unordered_map<RadicalStroke, int, RadicalStrokedHash> RSCounts;
6363

6464
// Helper function builds the RSMap from the radical-stroke file, which has
6565
// already been read into a STRING. Returns false on error.

ccutil/unicharcompress.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#ifndef TESSERACT_CCUTIL_UNICHARCOMPRESS_H_
2323
#define TESSERACT_CCUTIL_UNICHARCOMPRESS_H_
2424

25-
#include "hashfn.h"
25+
#include <unordered_map>
26+
2627
#include "serialis.h"
2728
#include "strngs.h"
2829
#include "unicharset.h"
@@ -236,17 +237,19 @@ class UnicharCompress {
236237
// encoder_ is the only part that is serialized. The rest is computed on load.
237238
GenericVector<RecodedCharID> encoder_;
238239
// Decoder converts the output of encoder back to a unichar-id.
239-
TessHashMap<RecodedCharID, int, RecodedCharID::RecodedCharIDHash> decoder_;
240+
std::unordered_map<RecodedCharID, int,
241+
RecodedCharID::RecodedCharIDHash>
242+
decoder_;
240243
// True if the index is a valid single or start code.
241244
GenericVector<bool> is_valid_start_;
242245
// Maps a prefix code to a list of valid next codes.
243246
// The map owns the vectors.
244-
TessHashMap<RecodedCharID, GenericVectorEqEq<int>*,
247+
std::unordered_map<RecodedCharID, GenericVectorEqEq<int>*,
245248
RecodedCharID::RecodedCharIDHash>
246249
next_codes_;
247250
// Maps a prefix code to a list of valid final codes.
248251
// The map owns the vectors.
249-
TessHashMap<RecodedCharID, GenericVectorEqEq<int>*,
252+
std::unordered_map<RecodedCharID, GenericVectorEqEq<int>*,
250253
RecodedCharID::RecodedCharIDHash>
251254
final_codes_;
252255
// Max of any value in encoder_ + 1.

lstm/lstmtrainer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ double LSTMTrainer::ComputeCharError(const GenericVector<int>& truth_str,
12111211
// Computes word recall error rate using a very simple bag of words algorithm.
12121212
// NOTE that this is destructive on both input strings.
12131213
double LSTMTrainer::ComputeWordError(STRING* truth_str, STRING* ocr_str) {
1214-
typedef TessHashMap<std::string, int, std::hash<std::string> > StrMap;
1214+
typedef std::unordered_map<std::string, int, std::hash<std::string> > StrMap;
12151215
GenericVector<STRING> truth_words, ocr_words;
12161216
truth_str->split(' ', &truth_words);
12171217
if (truth_words.empty()) return 0.0;

textord/bbgrid.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
#ifndef TESSERACT_TEXTORD_BBGRID_H_
2222
#define TESSERACT_TEXTORD_BBGRID_H_
2323

24+
#include <unordered_set>
25+
2426
#include "clst.h"
2527
#include "coutln.h"
26-
#include "hashfn.h"
2728
#include "rect.h"
2829
#include "scrollview.h"
2930

@@ -364,7 +365,7 @@ template<class BBC, class BBC_CLIST, class BBC_C_IT> class GridSearch {
364365
// An iterator over the list at (x_, y_) in the grid_.
365366
BBC_C_IT it_;
366367
// Set of unique returned elements used when unique_mode_ is true.
367-
TessHashSet<BBC*, PtrHash<BBC> > returns_;
368+
std::unordered_set<BBC*, PtrHash<BBC> > returns_;
368369
};
369370

370371
// Sort function to sort a BBC by bounding_box().left().

training/ligature_table.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const int kMinLigature = 0xfb00;
4646
const int kMaxLigature = 0xfb17; // Don't put the wide Hebrew letters in.
4747

4848
/* static */
49-
SmartPtr<LigatureTable> LigatureTable::instance_;
49+
std::unique_ptr<LigatureTable> LigatureTable::instance_;
5050

5151
/* static */
5252
LigatureTable* LigatureTable::Get() {

training/ligature_table.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
#define TRAININGDATA_LIGATURE_TABLE_H_
2424

2525
#include <string>
26+
#include <unordered_map>
27+
#include <memory>
2628

27-
#include "hashfn.h"
2829
#include "util.h"
2930

3031
namespace tesseract {
3132

3233
class PangoFontInfo; // defined in pango_font_info.h
3334

3435
// Map to substitute strings for ligatures.
35-
typedef TessHashMap<string, string, StringHash> LigHash;
36+
typedef std::unordered_map<string, string, StringHash> LigHash;
3637

3738
class LigatureTable {
3839
public:
@@ -61,7 +62,7 @@ class LigatureTable {
6162
// corresponding ligature characters.
6263
void Init();
6364

64-
static SmartPtr<LigatureTable> instance_;
65+
static std::unique_ptr<LigatureTable> instance_;
6566
LigHash norm_to_lig_table_;
6667
LigHash lig_to_norm_table_;
6768
int min_lig_length_;

training/pango_font_info.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ void FontUtils::GetAllRenderableCharacters(const vector<string>& fonts,
688688
// Utilities written to be backward compatible with StringRender
689689

690690
/* static */
691-
int FontUtils::FontScore(const TessHashMap<char32, inT64>& ch_map,
691+
int FontUtils::FontScore(const std::unordered_map<char32, inT64>& ch_map,
692692
const string& fontname, int* raw_score,
693693
vector<bool>* ch_flags) {
694694
PangoFontInfo font_info;
@@ -704,7 +704,7 @@ int FontUtils::FontScore(const TessHashMap<char32, inT64>& ch_map,
704704
}
705705
*raw_score = 0;
706706
int ok_chars = 0;
707-
for (TessHashMap<char32, inT64>::const_iterator it = ch_map.begin();
707+
for (std::unordered_map<char32, inT64>::const_iterator it = ch_map.begin();
708708
it != ch_map.end(); ++it) {
709709
bool covered = (IsWhitespace(it->first) ||
710710
(pango_coverage_get(coverage, it->first)
@@ -722,7 +722,7 @@ int FontUtils::FontScore(const TessHashMap<char32, inT64>& ch_map,
722722

723723

724724
/* static */
725-
string FontUtils::BestFonts(const TessHashMap<char32, inT64>& ch_map,
725+
string FontUtils::BestFonts(const std::unordered_map<char32, inT64>& ch_map,
726726
vector<pair<const char*, vector<bool> > >* fonts) {
727727
const double kMinOKFraction = 0.99;
728728
// Weighted fraction of characters that must be renderable in a font to make

training/pango_font_info.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#include <string>
2424
#include <utility>
2525
#include <vector>
26+
#include <unordered_map>
2627

2728
#include "commandlineflags.h"
28-
#include "hashfn.h"
2929
#include "host.h"
3030
#include "pango/pango-font.h"
3131
#include "pango/pango.h"
@@ -203,15 +203,15 @@ class FontUtils {
203203
// corresponding character (in order of iterating ch_map) can be rendered.
204204
// The return string is a list of the acceptable fonts that were used.
205205
static string BestFonts(
206-
const TessHashMap<char32, inT64>& ch_map,
206+
const std::unordered_map<char32, inT64>& ch_map,
207207
std::vector<std::pair<const char*, std::vector<bool> > >* font_flag);
208208

209209
// FontScore returns the weighted renderability score of the given
210210
// hash map character table in the given font. The unweighted score
211211
// is also returned in raw_score.
212212
// The values in the bool vector ch_flags correspond to whether the
213213
// corresponding character (in order of iterating ch_map) can be rendered.
214-
static int FontScore(const TessHashMap<char32, inT64>& ch_map,
214+
static int FontScore(const std::unordered_map<char32, inT64>& ch_map,
215215
const string& fontname, int* raw_score,
216216
std::vector<bool>* ch_flags);
217217

training/stringrenderer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
#include <string>
3333
#include <vector>
34+
#include <unordered_map>
3435

35-
#include "hashfn.h"
3636
#include "host.h"
3737
#include "pango_font_info.h"
3838
#include "pango/pango-layout.h"
@@ -210,7 +210,7 @@ class StringRenderer {
210210
Boxa* page_boxes_;
211211

212212
// Objects cached for subsequent calls to RenderAllFontsToImage()
213-
TessHashMap<char32, inT64> char_map_; // Time-saving char histogram.
213+
std::unordered_map<char32, inT64> char_map_; // Time-saving char histogram.
214214
int total_chars_; // Number in the string to be rendered.
215215
int font_index_; // Index of next font to use in font list.
216216
int last_offset_; // Offset returned from last successful rendering

0 commit comments

Comments
 (0)