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 "ChartTrellisDetourQueue.h" 00021 00022 #include "Util.h" 00023 00024 namespace Moses 00025 { 00026 00027 ChartTrellisDetourQueue::~ChartTrellisDetourQueue() 00028 { 00029 RemoveAllInColl(m_queue); 00030 } 00031 00032 void ChartTrellisDetourQueue::Push(const ChartTrellisDetour *detour) 00033 { 00034 if (m_capacity == 0 || m_queue.size() < m_capacity) { 00035 m_queue.insert(detour); 00036 } else if (detour->GetTotalScore() > (*m_queue.rbegin())->GetTotalScore()) { 00037 // Remove the worst-scoring item from the queue and insert detour. 00038 QueueType::iterator p = m_queue.end(); 00039 delete *--p; 00040 m_queue.erase(p); 00041 m_queue.insert(detour); 00042 } else { 00043 // The detour is unusable: the queue is full and detour has a worse (or 00044 // equal) score than the worst-scoring item already held. 00045 delete detour; 00046 } 00047 } 00048 00049 const ChartTrellisDetour *ChartTrellisDetourQueue::Pop() 00050 { 00051 QueueType::iterator p = m_queue.begin(); 00052 const ChartTrellisDetour *top = *p; 00053 m_queue.erase(p); 00054 return top; 00055 } 00056 00057 } // namespace Moses