clean up comparison functions for Words and Phrases

This commit is contained in:
Hieu Hoang 2015-10-17 20:59:52 +01:00
parent 563552aea6
commit 5754a46905
4 changed files with 11 additions and 12 deletions

View File

@ -43,7 +43,7 @@ GlobalLexicalModel::~GlobalLexicalModel()
// delete words in the hash data structure
DoubleHash::const_iterator iter;
for(iter = m_hash.begin(); iter != m_hash.end(); iter++ ) {
map< const Word*, float, WordComparer >::const_iterator iter2;
boost::unordered_map< const Word*, float, WordComparer, WordComparer>::const_iterator iter2;
for(iter2 = iter->second.begin(); iter2 != iter->second.end(); iter2++ ) {
delete iter2->first; // delete input word
}

View File

@ -33,8 +33,8 @@ class InputType;
*/
class GlobalLexicalModel : public StatelessFeatureFunction
{
typedef std::map< const Word*, std::map< const Word*, float, WordComparer >, WordComparer > DoubleHash;
typedef std::map< const Word*, float, WordComparer > SingleHash;
typedef boost::unordered_map< const Word*, boost::unordered_map< const Word*, float, WordComparer, WordComparer >, WordComparer, WordComparer > DoubleHash;
typedef boost::unordered_map< const Word*, float, WordComparer, WordComparer > SingleHash;
typedef std::map< const TargetPhrase*, float > LexiconCache;
struct ThreadLocalStorage {

View File

@ -44,7 +44,7 @@ typedef std::map < Word , ScoreComponentCollection > OutputWordCollection;
*/
class GenerationDictionary : public DecodeFeature
{
typedef std::map<const Word* , OutputWordCollection, WordComparer> Collection;
typedef boost::unordered_map<const Word* , OutputWordCollection, WordComparer, WordComparer> Collection;
protected:
static std::vector<GenerationDictionary*> s_staticColl;

View File

@ -130,11 +130,6 @@ public:
return !(*this == compare);
}
int Compare(const Word &other) const {
return Compare(*this, other);
}
/* static functions */
/** transitive comparison of 2 word objects. Used by operator<.
@ -159,10 +154,14 @@ public:
};
struct WordComparer {
//! returns true if hypoA can be recombined with hypoB
bool operator()(const Word *a, const Word *b) const {
return *a < *b;
size_t operator()(const Word* word) const {
return word->hash();
}
bool operator()(const Word* a, const Word* b) const {
return (*a) == (*b);
}
};