diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-01-21 23:21:47 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-01-21 23:21:47 +0400 |
commit | 40adac9f18233a2e17eee3adca0e4dbcbd7a488a (patch) | |
tree | af9b197591bb7d5cfc2b0f3a862c680e1819adb6 | |
parent | 05de672bd85b9df3c1b5ceea7db782a628bd3983 (diff) | |
parent | 39858ce1ff7d115e0022ccc7c55184a14c7f2932 (diff) |
Merge branch 'master' into hieu
-rw-r--r-- | moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp index ea60d4d23..45b881765 100644 --- a/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp +++ b/moses/TranslationModel/RuleTable/PhraseDictionaryOnDisk.cpp @@ -110,6 +110,14 @@ void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(const InputPathList InputPath &inputPath = **iter; GetTargetPhraseCollectionBatch(inputPath); } + + // delete nodes that's been saved + for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) { + InputPath &inputPath = **iter; + const OnDiskPt::PhraseNode *ptNode = static_cast<const OnDiskPt::PhraseNode*>(inputPath.GetPtNode(*this)); + delete ptNode; + } + } void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(InputPath &inputPath) const @@ -154,32 +162,25 @@ const TargetPhraseCollection *PhraseDictionaryOnDisk::GetTargetPhraseCollection( { const TargetPhraseCollection *ret; - if (m_maxCacheSize) { - CacheColl &cache = GetCache(); - size_t hash = (size_t) ptNode->GetFilePos(); - - std::map<size_t, std::pair<const TargetPhraseCollection*, clock_t> >::iterator iter; + CacheColl &cache = GetCache(); + size_t hash = (size_t) ptNode->GetFilePos(); - iter = cache.find(hash); + std::map<size_t, std::pair<const TargetPhraseCollection*, clock_t> >::iterator iter; - if (iter == cache.end()) { - // not in cache, need to look up from phrase table - ret = GetTargetPhraseCollectionNonCache(ptNode); - if (ret) { - ret = new TargetPhraseCollection(*ret); - } + iter = cache.find(hash); - std::pair<const TargetPhraseCollection*, clock_t> value(ret, clock()); - cache[hash] = value; - } else { - // in cache. just use it - std::pair<const TargetPhraseCollection*, clock_t> &value = iter->second; - value.second = clock(); + if (iter == cache.end()) { + // not in cache, need to look up from phrase table + ret = GetTargetPhraseCollectionNonCache(ptNode); - ret = value.first; - } + std::pair<const TargetPhraseCollection*, clock_t> value(ret, clock()); + cache[hash] = value; } else { - ret = GetTargetPhraseCollectionNonCache(ptNode); + // in cache. just use it + std::pair<const TargetPhraseCollection*, clock_t> &value = iter->second; + value.second = clock(); + + ret = value.first; } return ret; |