00001 // $Id$ 00002 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2006 University of Edinburgh 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 ***********************************************************************/ 00021 00022 #ifndef moses_TrellisPathCollection_h 00023 #define moses_TrellisPathCollection_h 00024 00025 #include <set> 00026 #include <iostream> 00027 #include "TrellisPath.h" 00028 00029 namespace Moses 00030 { 00031 00032 struct CompareTrellisPathCollection { 00033 bool operator()(const TrellisPath* pathA, const TrellisPath* pathB) const { 00034 return (pathA->GetFutureScore() > pathB->GetFutureScore()); 00035 } 00036 }; 00037 00042 class TrellisPathCollection 00043 { 00044 friend std::ostream& operator<<(std::ostream&, const TrellisPathCollection&); 00045 00046 protected: 00047 typedef std::multiset<TrellisPath*, CompareTrellisPathCollection> CollectionType; 00048 CollectionType m_collection; 00049 00050 public: 00051 //iterator begin() { return m_collection.begin(); } 00052 TrellisPath *pop() { 00053 TrellisPath *top = *m_collection.begin(); 00054 00055 // Detach 00056 m_collection.erase(m_collection.begin()); 00057 return top; 00058 } 00059 00060 ~TrellisPathCollection() { 00061 // clean up 00062 RemoveAllInColl(m_collection); 00063 } 00064 00066 void Add(TrellisPath *trellisPath) { 00067 m_collection.insert(trellisPath); 00068 } 00069 00070 size_t GetSize() const { 00071 return m_collection.size(); 00072 } 00073 00074 void Prune(size_t newSize); 00075 }; 00076 00077 inline std::ostream& operator<<(std::ostream& out, const TrellisPathCollection& pathColl) 00078 { 00079 TrellisPathCollection::CollectionType::const_iterator iter; 00080 00081 for (iter = pathColl.m_collection.begin() ; iter != pathColl.m_collection.end() ; ++iter) { 00082 const TrellisPath &path = **iter; 00083 out << path << std::endl; 00084 } 00085 return out; 00086 } 00087 00088 } 00089 00090 #endif