00001 /*********************************************************************** 00002 Moses - statistical machine translation system 00003 Copyright (C) 2006-2011 University of Edinburgh 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ***********************************************************************/ 00019 00020 #include <iostream> 00021 #include "HypothesisQueue.h" 00022 00023 using namespace std; 00024 00025 namespace Moses 00026 { 00027 00028 HypothesisQueue::~HypothesisQueue() 00029 { 00030 m_queue.clear(); 00031 } 00032 00033 void HypothesisQueue::Push(BleuIndexPair hypo) 00034 { 00035 //pair<set<BleuIndexPair>::iterator,bool> ret; 00036 00037 if (m_capacity == 0 || m_queue.size() < m_capacity) { 00038 m_queue.insert(hypo); 00039 } else if (hypo.first > (*(m_queue.rbegin())).first) { 00040 // Remove the worst-scoring item from the queue and insert hypo (only erase item if new item was successfully added ) 00041 /*ret = m_queue.insert(hypo); 00042 if ((*(ret.first)).second == 1) { 00043 HypoQueueType::iterator p = m_queue.end(); 00044 --p; 00045 m_queue.erase(p); 00046 }*/ 00047 // with multisets we do not have to check whether the item was successfully added 00048 m_queue.insert(hypo); 00049 HypoQueueType::iterator p = m_queue.end(); 00050 --p; 00051 m_queue.erase(p); 00052 } else { 00053 // The hypo is unusable: the queue is full and hypo has a worse (or 00054 // equal) score than the worst-scoring item already held. 00055 } 00056 } 00057 00058 BleuIndexPair HypothesisQueue::Pop() 00059 { 00060 HypoQueueType::iterator p = m_queue.begin(); 00061 BleuIndexPair top = *p; 00062 m_queue.erase(p); 00063 return top; 00064 } 00065 00066 } // namespace Moses