Always have a TargetPhraseCollection.

Before:
Name:moses_chart        VmPeak:12027904 kB      VmRSS:10151884 kB       real:173.000
real    2m53.608s
user    2m44.003s
sys     0m8.401s

After:
Name:moses_chart        VmPeak:11988700 kB      VmRSS:10112684 kB       real:177.500
real    2m58.393s
user    2m39.673s
sys     0m12.171s
This commit is contained in:
Kenneth Heafield 2013-07-12 06:49:52 -07:00
parent 23c2530617
commit 1b3f769c5c
4 changed files with 16 additions and 30 deletions

View File

@ -36,6 +36,7 @@ class TargetPhraseCollection
protected: protected:
friend std::ostream& operator<<(std::ostream &, const TargetPhraseCollection &); friend std::ostream& operator<<(std::ostream &, const TargetPhraseCollection &);
// TODO boost::ptr_vector
std::vector<TargetPhrase*> m_collection; std::vector<TargetPhrase*> m_collection;
public: public:
@ -57,7 +58,7 @@ public:
} }
~TargetPhraseCollection() { ~TargetPhraseCollection() {
RemoveAllInColl(m_collection); Clear();
} }
const std::vector<TargetPhrase*> &GetCollection() const { const std::vector<TargetPhrase*> &GetCollection() const {
@ -83,6 +84,10 @@ public:
void Prune(bool adhereTableLimit, size_t tableLimit); void Prune(bool adhereTableLimit, size_t tableLimit);
void Sort(bool adhereTableLimit, size_t tableLimit); void Sort(bool adhereTableLimit, size_t tableLimit);
void Clear() {
RemoveAllInColl(m_collection);
}
}; };
} }

View File

@ -70,14 +70,7 @@ const TargetPhraseCollection *PhraseDictionaryMemory::GetTargetPhraseCollection(
return NULL; return NULL;
} }
const TargetPhraseCollection *coll = currNode->GetTargetPhraseCollection(); return currNode->GetTargetPhraseCollection();
/*
if (coll) {
cerr << "source=" << source << endl
<< *coll << endl;
}
*/
return coll;
} }
PhraseDictionaryNodeMemory &PhraseDictionaryMemory::GetOrCreateNode(const Phrase &source PhraseDictionaryNodeMemory &PhraseDictionaryMemory::GetOrCreateNode(const Phrase &source

View File

@ -38,14 +38,6 @@ PhraseDictionaryNodeMemory::~PhraseDictionaryNodeMemory()
const PhraseDictionaryNodeMemory *node = iter->second; const PhraseDictionaryNodeMemory *node = iter->second;
delete node; delete node;
} }
delete m_targetPhraseCollection;
}
TargetPhraseCollection &PhraseDictionaryNodeMemory::GetOrCreateTargetPhraseCollection()
{
if (m_targetPhraseCollection == NULL)
m_targetPhraseCollection = new TargetPhraseCollection();
return *m_targetPhraseCollection;
} }
void PhraseDictionaryNodeMemory::Prune(size_t tableLimit) void PhraseDictionaryNodeMemory::Prune(size_t tableLimit)
@ -59,8 +51,7 @@ void PhraseDictionaryNodeMemory::Prune(size_t tableLimit)
} }
// prune TargetPhraseCollection in this node // prune TargetPhraseCollection in this node
if (m_targetPhraseCollection != NULL) m_targetPhraseCollection.Prune(true, tableLimit);
m_targetPhraseCollection->Prune(true, tableLimit);
} }
void PhraseDictionaryNodeMemory::Sort(size_t tableLimit) void PhraseDictionaryNodeMemory::Sort(size_t tableLimit)
@ -74,9 +65,7 @@ void PhraseDictionaryNodeMemory::Sort(size_t tableLimit)
} }
// prune TargetPhraseCollection in this node // prune TargetPhraseCollection in this node
if (m_targetPhraseCollection != NULL) { m_targetPhraseCollection.Sort(true, tableLimit);
m_targetPhraseCollection->Sort(true, tableLimit);
}
} }
PhraseDictionaryNodeMemory *PhraseDictionaryNodeMemory::GetOrCreateChild(const Word &sourceTerm) PhraseDictionaryNodeMemory *PhraseDictionaryNodeMemory::GetOrCreateChild(const Word &sourceTerm)
@ -138,8 +127,7 @@ void PhraseDictionaryNodeMemory::Clear()
{ {
m_sourceTermMap.clear(); m_sourceTermMap.clear();
m_nonTermMap.clear(); m_nonTermMap.clear();
delete m_targetPhraseCollection; m_targetPhraseCollection.Clear();
} }
std::ostream& operator<<(std::ostream &out, const PhraseDictionaryNodeMemory &node) std::ostream& operator<<(std::ostream &out, const PhraseDictionaryNodeMemory &node)

View File

@ -120,14 +120,12 @@ private:
friend class std::map<Word, PhraseDictionaryNodeMemory>; friend class std::map<Word, PhraseDictionaryNodeMemory>;
friend class std::map<long, PhraseDictionaryNodeMemory>; friend class std::map<long, PhraseDictionaryNodeMemory>;
protected:
TerminalMap m_sourceTermMap; TerminalMap m_sourceTermMap;
NonTerminalMap m_nonTermMap; NonTerminalMap m_nonTermMap;
TargetPhraseCollection *m_targetPhraseCollection; TargetPhraseCollection m_targetPhraseCollection;
PhraseDictionaryNodeMemory() {}
PhraseDictionaryNodeMemory()
:m_targetPhraseCollection(NULL) {
}
public: public:
~PhraseDictionaryNodeMemory(); ~PhraseDictionaryNodeMemory();
@ -143,9 +141,11 @@ public:
const PhraseDictionaryNodeMemory *GetChild(const Word &sourceNonTerm, const Word &targetNonTerm) const; const PhraseDictionaryNodeMemory *GetChild(const Word &sourceNonTerm, const Word &targetNonTerm) const;
const TargetPhraseCollection *GetTargetPhraseCollection() const { const TargetPhraseCollection *GetTargetPhraseCollection() const {
return &m_targetPhraseCollection;
}
TargetPhraseCollection &GetOrCreateTargetPhraseCollection() {
return m_targetPhraseCollection; return m_targetPhraseCollection;
} }
TargetPhraseCollection &GetOrCreateTargetPhraseCollection();
const NonTerminalMap & GetNonTerminalMap() const { const NonTerminalMap & GetNonTerminalMap() const {
return m_nonTermMap; return m_nonTermMap;