Skip to content

Commit

Permalink
Merge pull request tesseract-ocr#662 from amitdo/remove-hashfn2
Browse files Browse the repository at this point in the history
Remove code that is no longer needed
  • Loading branch information
zdenop authored Jan 16, 2017
2 parents 080eb73 + 5d627aa commit 170573f
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 102 deletions.
2 changes: 1 addition & 1 deletion ccutil/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 0 additions & 80 deletions ccutil/hashfn.h

This file was deleted.

4 changes: 2 additions & 2 deletions ccutil/unicharcompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions ccutil/unicharcompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lstm/lstmtrainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions textord/bbgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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().
Expand Down
2 changes: 1 addition & 1 deletion training/ligature_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions training/ligature_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
#define TRAININGDATA_LIGATURE_TABLE_H_

#include <string>
#include <unordered_map>
#include <memory>

#include "hashfn.h"
#include "util.h"

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:
Expand Down Expand Up @@ -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_;
Expand Down
6 changes: 3 additions & 3 deletions training/pango_font_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions training/pango_font_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -203,15 +203,15 @@ 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
// hash map character table in the given font. The unweighted score
// 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);

Expand Down
4 changes: 2 additions & 2 deletions training/stringrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 170573f

Please sign in to comment.